calculate patch of rgb image

2 visualizaciones (últimos 30 días)
Pam
Pam el 24 de Sept. de 2013
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

Respuesta aceptada

Image Analyst
Image Analyst el 24 de Sept. de 2013
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 comentarios
Pam
Pam el 25 de Sept. de 2013
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 el 25 de Sept. de 2013
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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by