calculate patch of rgb image
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 24 Sep. 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 Kommentare
Image Analyst
am 25 Sep. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!