Bilinear filtering, help!

20 visualizaciones (últimos 30 días)
Omid
Omid el 28 de Sept. de 2011
Hi, I'm really new to matlab programming and in general to image processing. I need some guidance with trying to filter images in the form of "Bayer Demosaicing" I found a code on the file exchange and I tried working with it and changing it around. But I've come up with some problems. firstly, why is it when I do convolution on the image it always ends up changing the size of the matrix? for example it will go from 334x500 to 336x502, resulting in an error when I try to perform other operations with it since the matrix is not the same size as the others. And does the code even make sense? I'm following some guidance that I received elsewhere with making this type of filter. I'm really stuck on normalizing the convolutions.
Please, any help will greatly be appreciated.
Here's the code I'm using with the my additions.
im=imread('kids.jpg');
im=im2double(im);
M = size(im, 1);
N = size(im, 2);
channel = size(size(im), 2); % == 2 => one channel
% == 3 => three channel
red_mask = repmat([0 1; 0 0], M/2, N/2);
green_mask = repmat([1 0; 0 1], M/2, N/2);
blue_mask = repmat([0 0; 1 0], M/2, N/2);
%extracting red,green,blue values from input
if channel == 2
R=im.*red_mask;
G=im.*green_mask;
B=im.*blue_mask;
elseif channel == 3
R=im(:,:,1).*red_mask;
G=im(:,:,2).*green_mask;
B=im(:,:,3).*blue_mask;
end
% Interpolation of the red,green and blue matrices. convolve each with a 3x3 matrix of ones.
G=conv2(G, ones(3)./9, 'same');
B=conv2(B,ones(3)./9,'same');
R=conv2(R, ones(3)./9,'same');
%normalize the output of the convolution. This is needed because the number of %nonzero input values is not equal in all 3x3 neighborhoods. first convolve the %grid matrices containing only zeros and ones with the 3x3 convolution matrix. %this will compute the number elements in each neighborhood. next you should %perform an element wise division of the outputs of the previous step with the %corresponding normalization matrices.
R1 = conv2(R,[0 1 0; 0 0 0; 0 1 0]);
G1 = conv2(G, [1 0 1; 0 1 0; 1 0 1]/4);
B1 = conv2(B,[0 0 0; 1 0 1; 0 0 0]);
R=R1./(R);
G=G1./(G);
B=B1./(B);
output(:,:,1)=R; output(:,:,2)=G; output(:,:,3)=B;
imshow(output);

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by