Bilinear Interpolation 3 channel raw image

4 Ansichten (letzte 30 Tage)
Kat
Kat am 5 Mai 2014
Beantwortet: Taha am 26 Mai 2017
I'm trying to do bilinear interpolation on a raw image converted into a tif. The other raw image I obtained from my class is merged into 1 channel and that works perfectly, while this raw image I captured has three channels and won't run. When I try to run this code for the image with 3 channels, it always says
'Error using .* Matrix dimensions must agree.'
I've tried to assign each bands as R,G,B respectively and concatenating but I still run into the same error. Any ides how I can get this to work on my 3 channel images? My code is as follows:
clc;
close all;
clear all;
% Read in raw image
Raw = imread('upbayer.tif');
% Define the RGB arrays
[row,col] = size(Raw);
Bilinear interpolation
%create bayer pattern
i=double(Raw);
im =zeros([row col 3]);
row = size(i, 1);
col = size(i, 2);
channel = size(size(i), 2); % 2 = one channel
red_mask = repmat([0 1; 0 0], floor(row/2), floor(col/2));
green_mask = repmat([1 0; 0 1], floor(row/2), floor(col/2));
blue_mask = repmat([0 0; 1 0], floor(row/2), floor(col/2));
R=i.*red_mask;
G=i.*green_mask;
B=i.*blue_mask;
im(:,:,1)=R;
im(:,:,2)=G;
im(:,:,3)=B;
%interpolation
% interpolate for blue
% blue at red pixels
B1 = imfilter(B,[1 0 1; 0 0 0; 1 0 1]/4);
% blue at green pixels
B2 = imfilter(B+B1,[0 1 0; 1 0 1; 0 1 0]/4);
B = B + B1 + B2;
% interpolate for red
% red at blue pixels
R1 = imfilter(R,[1 0 1; 0 0 0; 1 0 1]/4);
% red at green pixels
R2 = imfilter(R+R1,[0 1 0; 1 0 1; 0 1 0]/4);
R = R + R1 + R2;
% interpolate for green
% creating this to output an image of bilinear interpolation
G= G + imfilter(G, [0 1 0; 1 0 1; 0 1 0]/4);
figure(2)
bilinear(:,:,1)=R;
bilinear(:,:,2)=G;
bilinear(:,:,3)=B;
imshow(uint8(bilinear))
The dimensions I have for the variables are:
channel 3
row 3264
col 4912
red_mask 3264x4912
green_mask 3264x4912
blue_mask 3264x4912

Antworten (1)

Taha
Taha am 26 Mai 2017
The following changes will make the code work:
R=i(:,:,1).*red_mask;
G=i(:,:,2).*green_mask;
B=i(:,:,3).*blue_mask;

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by