Skip to content

Commit

Permalink
Add debayering normalization for PixelFormat::BAYER8_RGGB
Browse files Browse the repository at this point in the history
Summary:
BAYER8_RGGB is currently displayed as if it was a grey8 image, which is very approximative. This diff adds a meta-only code path in which we debayer these images.
Because debayering very large images is slow, we use a debayering + downsampler algorithm for display, but with large images only.

Reviewed By: maxouellet

Differential Revision: D63151489

fbshipit-source-id: 119a047d4a0e362daa1c033caf8c90abacbc3468
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Sep 26, 2024
1 parent be43e67 commit b9d8674
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tools/vrsplayer/FramePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool FramePlayer::onImageRead(
if (frameValid) {
normalizeOptions_ = PixelFrame::getStreamNormalizeOptions(
*record.fileReader, record.streamId, frame->getPixelFormat());
normalizeOptions_.speedOverPrecision = frame->getWidth() * frame->getHeight() >= 4000 * 4000;
}
fmt::print(
"Found '{} - {}': {}, {}",
Expand Down Expand Up @@ -235,7 +236,10 @@ bool FramePlayer::saveFrame(
shared_ptr<PixelFrame> frame;
if (PixelFrame::readRawFrame(frame, record.reader, spec)) {
shared_ptr<PixelFrame> normalizedFrame;
bool speedOverPrecision = normalizeOptions_.speedOverPrecision;
normalizeOptions_.speedOverPrecision = false;
PixelFrame::normalizeFrame(frame, normalizedFrame, true, normalizeOptions_);
normalizeOptions_.speedOverPrecision = speedOverPrecision;
if (normalizedFrame->writeAsPng(saveNextFramePath_) == 0) {
XR_LOGI("Saved raw frame as '{}'", saveNextFramePath_);
}
Expand Down
4 changes: 4 additions & 0 deletions vrs/utils/PixelFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ PixelFormat PixelFrame::getNormalizedPixelFormat(
options.semantic == ImageSemantic::ObjectIdSegmentation) &&
sourcePixelFormat == PixelFormat::GREY16) {
format = PixelFormat::RGB8;
#if IS_VRS_FB_INTERNAL()
} else if (format == PixelFormat::BAYER8_RGGB) {
format = PixelFormat::RGB8;
#endif
} else {
format = ImageContentBlockSpec::getChannelCountPerPixel(sourcePixelFormat) > 1
? PixelFormat::RGB8
Expand Down
4 changes: 2 additions & 2 deletions vrs/utils/PixelFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ struct NormalizeOptions {
: semantic{semantic}, min{min}, max{max} {}

ImageSemantic semantic{ImageSemantic::Undefined};
bool speedOverPrecision{false}; // prefer speed (for display?) or precision (to save to disk?)
float min{0};
float max{0};
};

/// Helper class to read & convert images read using RecordFormat into simpler, but maybe degraded,
/// pixel buffer, that can easily be displayed, or saved to disk as jpg or png.
///
/// Here are the "conversions" performed overall:
/// Here are some of the "normalizations" performed:
/// - GREY10, GREY12 and GREY16 to GREY8, by pixel depth reduction.
/// - RGB10 and RGB12 to RGB8, by pixel depth reduction.
/// - YUV_I420_SPLIT and YUY2 to RGB8, by conversion.
/// - DEPTH32F and SCALAR64F to GREY8, by normalization.
///
/// RGB32F is not currently not supported.
class PixelFrame {
public:
PixelFrame() = default;
Expand Down

0 comments on commit b9d8674

Please sign in to comment.