MATLAB: Color image into blocks

image processing

i wrote a code to convert color image into blocks… the output looks like the input image in grayscale with gridlines over it… can i get the output with gridlines over the color input image i give…. please do reply
rgbimage = imread('peppers.png');
patchsize = 10;
imsize = 10*25;
rgbimage = imresize(rgbimage ,[imsize imsize]);
image_out = [];
for i = 1:patchsize:imsize
image_out_tmp = [];
for j = 1:patchsize:imsize
tmp_img = rgbimage ((i+1-1):i+patchsize-1,(j+1-1):j+patchsize-1);
tmp_img = [ones(patchsize,1) tmp_img ones(patchsize,1)];
tmp_img = [ones(1,patchsize+2);tmp_img;ones(1,patchsize+2)];
image_out_tmp = [image_out_tmp tmp_img];
end
image_out = [image_out;image_out_tmp];
end
figure;imshow(image_out);

Best Answer

% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Now draw your lines in the channels for every row and column that you want.
redChannel(row, :) = 0;
greenChannel(row, :) = 0;
blueChannel(row, :) = 0;
redChannel(:, column) = 0;
greenChannel(:, column) = 0;
blueChannel(:, column) = 0;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);