Bilinear Interpolation 3 channel raw image
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
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
0 个评论
回答(1 个)
  Taha
 2017-5-26
        The following changes will make the code work:
 R=i(:,:,1).*red_mask;
 G=i(:,:,2).*green_mask;
 B=i(:,:,3).*blue_mask;
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

