Skip to content

Commit f821f54

Browse files
committed
Changed the logic of CFA mapping from source image (read from file) to the target image.
The goal is to maintain the same resolution and FOV with any SensorType. Now, each pixel in the source image corresponds to one pixel in the final image, but filtered through the color filter of the cell.
1 parent b676fc6 commit f821f54

1 file changed

Lines changed: 76 additions & 40 deletions

File tree

Camera.Simulator/Camera.cs

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,60 +3150,96 @@ private void MonochromeData(int x, int y)
31503150

31513151
private void RGGBData(int x, int y)
31523152
{
3153-
var px = bmp[x / 2, y / 2];
3154-
imageData[x + x0, y + y0, 0] = px.R; // red
3155-
imageData[x + x1, y + y0, 0] = px.G; // green
3156-
imageData[x + x0, y + y1, 0] = px.G; // green
3157-
imageData[x + x1, y + y1, 0] = px.B; // blue
3153+
var px00 = bmp[x + 0, y + 0];
3154+
var px10 = bmp[x + 1, y + 0];
3155+
var px01 = bmp[x + 0, y + 1];
3156+
var px11 = bmp[x + 1, y + 1];
3157+
3158+
imageData[x + x0, y + y0, 0] = px00.R; // red
3159+
imageData[x + x1, y + y0, 0] = px10.G; // green
3160+
imageData[x + x0, y + y1, 0] = px01.G; // green
3161+
imageData[x + x1, y + y1, 0] = px11.B; // blue
31583162
}
31593163

31603164
private void CMYGData(int x, int y)
31613165
{
3162-
var px = bmp[x / 2, y / 2];
3163-
imageData[x + x0, y + y0, 0] = (px.R + px.G) / 2; // yellow
3164-
imageData[x + x1, y + y0, 0] = (px.G + px.B) / 2; // cyan
3165-
imageData[x + x0, y + y1, 0] = px.G; // green
3166-
imageData[x + x1, y + y1, 0] = (px.R + px.B) / 2; // magenta
3166+
var px00 = bmp[x + 0, y + 0];
3167+
var px10 = bmp[x + 1, y + 0];
3168+
var px01 = bmp[x + 0, y + 1];
3169+
var px11 = bmp[x + 1, y + 1];
3170+
3171+
imageData[x + x0, y + y0, 0] = (px00.R + px00.G) / 2; // yellow
3172+
imageData[x + x1, y + y0, 0] = (px10.G + px10.B) / 2; // cyan
3173+
imageData[x + x0, y + y1, 0] = px01.G; // green
3174+
imageData[x + x1, y + y1, 0] = (px11.R + px11.B) / 2; // magenta
31673175
}
31683176

31693177
private void CMYG2Data(int x, int y)
31703178
{
3171-
var px = bmp[x / 2, y / 2];
3172-
imageData[x + x0, y + y0, 0] = (px.G);
3173-
imageData[x + x1, y + y0, 0] = (px.B + px.R) / 2; // magenta
3174-
imageData[x + x0, y + y1, 0] = (px.G + px.B) / 2; // cyan
3175-
imageData[x + x1, y + y1, 0] = (px.R + px.G) / 2; // yellow
3176-
px = bmp[x / 2, (y / 2) + 1];
3177-
imageData[x + x0, y + y2, 0] = (px.B + px.R) / 2; // magenta
3178-
imageData[x + x1, y + y2, 0] = (px.G);
3179-
imageData[x + x0, y + y3, 0] = (px.G + px.B) / 2; // cyan
3180-
imageData[x + x1, y + y3, 0] = (px.R + px.G) / 2; // yellow
3179+
var px00 = bmp[x + 0, y + 0];
3180+
var px10 = bmp[x + 1, y + 0];
3181+
var px01 = bmp[x + 0, y + 1];
3182+
var px11 = bmp[x + 1, y + 1];
3183+
3184+
var px02 = bmp[x + 0, y + 0];
3185+
var px12 = bmp[x + 1, y + 0];
3186+
var px03 = bmp[x + 0, y + 1];
3187+
var px13 = bmp[x + 1, y + 1];
3188+
3189+
imageData[x + x0, y + y0, 0] = (px00.G); // green
3190+
imageData[x + x1, y + y0, 0] = (px10.B + px10.R) / 2; // magenta
3191+
imageData[x + x0, y + y1, 0] = (px01.G + px01.B) / 2; // cyan
3192+
imageData[x + x1, y + y1, 0] = (px11.R + px11.G) / 2; // yellow
3193+
3194+
imageData[x + x0, y + y2, 0] = (px02.B + px02.R) / 2; // magenta
3195+
imageData[x + x1, y + y2, 0] = (px12.G); // green
3196+
imageData[x + x0, y + y3, 0] = (px03.G + px03.B) / 2; // cyan
3197+
imageData[x + x1, y + y3, 0] = (px13.R + px13.G) / 2; // yellow
31813198
}
31823199

31833200
private void LRGBData(int x, int y)
31843201
{
31853202
ColorSpaceConverter converter = new ColorSpaceConverter();
31863203

3187-
var px = bmp[x / 2, y / 2];
3188-
imageData[x + x0, y + y0, 0] = converter.ToHsl(px).L * 255;
3189-
imageData[x + x1, y + y0, 0] = (px.R);
3190-
imageData[x + x0, y + y1, 0] = (px.R);
3191-
imageData[x + x1, y + y1, 0] = converter.ToHsl(px).L * 255;
3192-
px = bmp[(x / 2) + 1, y / 2];
3193-
imageData[x + x2, y + y0, 0] = converter.ToHsl(px).L * 255;
3194-
imageData[x + x3, y + y0, 0] = (px.G);
3195-
imageData[x + x2, y + y1, 0] = (px.G);
3196-
imageData[x + x3, y + y1, 0] = converter.ToHsl(px).L * 255;
3197-
px = bmp[x / 2, (y / 2) + 1];
3198-
imageData[x + x0, y + y2, 0] = converter.ToHsl(px).L * 255;
3199-
imageData[x + x1, y + y2, 0] = (px.G);
3200-
imageData[x + x0, y + y3, 0] = (px.G);
3201-
imageData[x + x1, y + y3, 0] = converter.ToHsl(px).L * 255;
3202-
px = bmp[(x / 2) + 1, (y / 2) + 1];
3203-
imageData[x + x2, y + y2, 0] = converter.ToHsl(px).L * 255;
3204-
imageData[x + x3, y + y2, 0] = (px.B);
3205-
imageData[x + x2, y + y3, 0] = (px.B);
3206-
imageData[x + x3, y + y3, 0] = converter.ToHsl(px).L * 255;
3204+
var px00 = bmp[x + 0, y + 0];
3205+
var px10 = bmp[x + 1, y + 0];
3206+
var px20 = bmp[x + 0, y + 0];
3207+
var px30 = bmp[x + 1, y + 0];
3208+
3209+
var px01 = bmp[x + 0, y + 1];
3210+
var px11 = bmp[x + 1, y + 1];
3211+
var px21 = bmp[x + 0, y + 1];
3212+
var px31 = bmp[x + 1, y + 1];
3213+
3214+
var px02 = bmp[x + 0, y + 1];
3215+
var px12 = bmp[x + 1, y + 1];
3216+
var px22 = bmp[x + 0, y + 1];
3217+
var px32 = bmp[x + 1, y + 1];
3218+
3219+
var px03 = bmp[x + 0, y + 1];
3220+
var px13 = bmp[x + 1, y + 1];
3221+
var px23 = bmp[x + 0, y + 1];
3222+
var px33 = bmp[x + 1, y + 1];
3223+
3224+
imageData[x + x0, y + y0, 0] = converter.ToHsl(px00).L * 255;
3225+
imageData[x + x1, y + y0, 0] = (px10.R);
3226+
imageData[x + x0, y + y1, 0] = (px01.R);
3227+
imageData[x + x1, y + y1, 0] = converter.ToHsl(px11).L * 255;
3228+
3229+
imageData[x + x2, y + y0, 0] = converter.ToHsl(px20).L * 255;
3230+
imageData[x + x3, y + y0, 0] = (px30.G);
3231+
imageData[x + x2, y + y1, 0] = (px21.G);
3232+
imageData[x + x3, y + y1, 0] = converter.ToHsl(px31).L * 255;
3233+
3234+
imageData[x + x0, y + y2, 0] = converter.ToHsl(px02).L * 255;
3235+
imageData[x + x1, y + y2, 0] = (px12.G);
3236+
imageData[x + x0, y + y3, 0] = (px03.G);
3237+
imageData[x + x1, y + y3, 0] = converter.ToHsl(px13).L * 255;
3238+
3239+
imageData[x + x2, y + y2, 0] = converter.ToHsl(px22).L * 255;
3240+
imageData[x + x3, y + y2, 0] = (px32.B);
3241+
imageData[x + x2, y + y3, 0] = (px23.B);
3242+
imageData[x + x3, y + y3, 0] = converter.ToHsl(px33).L * 255;
32073243
}
32083244

32093245
private void ColorData(int x, int y)

0 commit comments

Comments
 (0)