calculate patch of rgb image

2 次查看(过去 30 天)
Hello
I have a 320x200x3 rgb image. I'd like to calculate 4x4 pixels patch from top to bottom and left to right for finding the average value of each patch. Could you please suggest me calculating without for loop (or less in use a loop)
Thank you

采纳的回答

Image Analyst
Image Analyst 2013-9-24
What are you averaging? The whole 4x4x4 cube? Or just a 2D 4x4 square on a color channel by color channel basis? And more importantly, why?
You can extract the color channels and get the average like this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
kernel = ones(4)/16;
blurredRed = conv2(double(redChannel), kernel, 'same');
blurredGreen = conv2(double(greenChannel), kernel, 'same');
blurredGreen = conv2(double(blueChannel), kernel, 'same');
blurredRGB = cat(3, blurredRed, blurredGreen, blurredBlue);
Or you can blur the colors while mixing colors by using convn
blurredRGB = convn(double(rgbImage), ones(4,4,4)/64, 'same');
  2 个评论
Pam
Pam 2013-9-25
Thank you for your answer.
I'd like to average a 2D 4x4 on R G and B in order to reduce cost of processing.
Image Analyst
Image Analyst 2013-9-25
What does that mean? Doing that will only add to processing time. Plus doing it for even number of elements is unusual because it gives you a half pixel shift in the image. Finally you haven't said if you want to average over color planes or keep them separate.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by