|
|
@ -209,7 +209,7 @@ function xc = bayer2rgb(xb, M, N, method) |
|
|
|
|
|
|
|
for currentCol = 1:N |
|
|
|
if ((mod(centerPointRow(currentRow), 2) == 0 && ... |
|
|
|
mod(centerPointCol(currentCol), 2)) == 0 || ... |
|
|
|
mod(centerPointCol(currentCol), 2) == 0) || ... |
|
|
|
(mod(centerPointRow(currentRow), 2) ~= 0 && ... |
|
|
|
mod(centerPointCol(currentCol), 2) ~= 0)) |
|
|
|
% This point of the original image DOES contain |
|
|
@ -248,11 +248,11 @@ function xc = bayer2rgb(xb, M, N, method) |
|
|
|
fixedCenterPointCol = centerPointCol(currentCol) + 1; |
|
|
|
end |
|
|
|
|
|
|
|
if (fixedCenterPointRow < 1) |
|
|
|
% Fix for the marginal first row case |
|
|
|
fixedCenterPointRow = 1; |
|
|
|
fixedCenterPointCol = fixedCenterPointCol - 1; |
|
|
|
end |
|
|
|
% if (fixedCenterPointRow < 1) |
|
|
|
% % Fix for the marginal first row case |
|
|
|
% fixedCenterPointRow = 1; |
|
|
|
% fixedCenterPointCol = fixedCenterPointCol - 1; |
|
|
|
% end |
|
|
|
|
|
|
|
xc.green(currentRow, currentCol) = ... |
|
|
|
tiltedInterp(gridPointsCoordinatesX(currentCol), ... |
|
|
@ -277,6 +277,29 @@ end |
|
|
|
|
|
|
|
|
|
|
|
function value = tiltedInterp(xw, yw, xc, yc, xbPadded) |
|
|
|
% Rotates the nearest points by 45 degrees |
|
|
|
x1 = (xc - 1) * cosd(45) - yc * sind(45); |
|
|
|
y1 = (xc - 1) * sind(45) + yc * cosd(45); |
|
|
|
|
|
|
|
x2 = (xc + 1) * cosd(45) - yc * sind(45); |
|
|
|
y2 = xc * sind(45) + (yc + 1) * cosd(45); |
|
|
|
|
|
|
|
lowerLeftInterpPoint = ... |
|
|
|
((x2 - xw) / (x2 - x1)) * ... |
|
|
|
xbPadded(yc + 2, xc - 1 + 2) + ... |
|
|
|
((xw - x1) / (x2 - x1)) * ... |
|
|
|
xbPadded(yc + 1 + 2, xc + 2); |
|
|
|
|
|
|
|
upperRightInterpPoint = ... |
|
|
|
((x2 - xw) / (x2 - x1)) * ... |
|
|
|
xbPadded(yc - 1 + 2, xc + 2) + ... |
|
|
|
((xw - x1) / (x2 - x1)) * ... |
|
|
|
xbPadded(yc + 2, xc + 1 + 2); |
|
|
|
|
|
|
|
value2 = ... |
|
|
|
(y2 - yw) / (y2 - y1) * lowerLeftInterpPoint + ... |
|
|
|
(yw - y1) / (y2 - y1) * upperRightInterpPoint; |
|
|
|
|
|
|
|
% Calculates the vertical displacement of the main diagonal that |
|
|
|
% crosses this point |
|
|
|
bw = yw - xw; |
|
|
@ -289,9 +312,9 @@ function value = tiltedInterp(xw, yw, xc, yc, xbPadded) |
|
|
|
% the lower point and the left point |
|
|
|
dist = sqrt((x1 - xw) ^ 2 + (x1 + bw - yw) ^ 2); |
|
|
|
|
|
|
|
% Calculates the lengths of the upper parts of the lines connecting the |
|
|
|
% Calculates the length of the upper part of the line connecting the |
|
|
|
% points |
|
|
|
h1 = sqrt(((xc - 1 - xw) ^ 2 + (yc - yw) ^ 2) - dist ^ 2); |
|
|
|
h1 = abs(sqrt(((xc - 1 - xw) ^ 2 + (yc - yw) ^ 2) - dist ^ 2)); |
|
|
|
|
|
|
|
lowerLeftInterpPoint = ... |
|
|
|
((sqrt(2) - h1) / sqrt(2)) * ... |
|
|
@ -308,18 +331,12 @@ function value = tiltedInterp(xw, yw, xc, yc, xbPadded) |
|
|
|
value = ... |
|
|
|
(sqrt(2) - dist) / sqrt(2) * lowerLeftInterpPoint + ... |
|
|
|
dist / sqrt(2) * upperRightInterpPoint; |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = (xbPadded(yc + 2, xc - 1 + 2) + ... |
|
|
|
xbPadded(yc + 2, xc + 1 + 2) + ... |
|
|
|
xbPadded(yc - 1 + 2, xc + 2) + ... |
|
|
|
xbPadded(yc + 1 + 2, xc + 2)) / 4; |
|
|
|
% if (value ~= value2) |
|
|
|
% disp(1); |
|
|
|
% end |
|
|
|
end |
|
|
|