close all;
Irgb=imread('barbara1.bmp');
figure,imshow(Irgb);
img=imread('CFA_rgbg.bmp');
% figure,imshow(Irgb);
% convert if array is type uint8
if (isa(img,'uint8'))
img=double(img)/255;
end
[m n l]=size(img);
y1=img(:,:,1);
figure,imshow(img);
for i=2:285
for j=2:355
y = (i-1)*2+1;
x = (j-1)*2+1;
y1(y+1,x)=(y1(y,x+1)+y1(y+2,x+1)+y1(y,x-1)+y1(y+2,x-1))/4;
y1(y,x)=(y1(y,x-1)+y1(y,x+1))/2;
y1(y+1,x+1)=(y1(y,x+1)+y1(y+2,x+1))/2;
end
end
figure,imshow(y1);
y2=img(:,:,2);
for i=2:285
for j=2:355
y = (i-1)*2+1;
x = (j-1)*2+1;
y2(y,x+1)=(y2(y,x)+y2(y,x+2)+y2(y+1,x+1)+y2(y-1,x+1))/4;
y2(y+1,x)=(y2(y,x)+y2(y+2,x)+y2(y+1,x+1)+y2(y+1,x-1))/4;
end
end
figure,imshow(y2);
y3=img(:,:,3);
for i=2:285
for j=2:355
y = (i-1)*2+1;
x = (j-1)*2+1;
y3(y,x)=(y3(y-1,x)+y3(y+1,x))/2;
y3(y,x+1)=(y3(y-1,x)+y3(y+1,x)+y3(y-1,x+2)+y3(y+1,x+2))/4;
y3(y+1,x+1)=(y3(y+1,x)+y3(y+1,x+2))/4;
end
end
figure,imshow(y2);
f=cat(3,y1,y2,y3);
figure,imshow(f);
评论0