Error while finding mean and variance using blockproc of an image
Mostrar comentarios más antiguos
I have a blockproc function as follows:
function [mean_ch,variance] = block_process(subchannel)
fun1 = @(block_struct) mean(subchannel(:));
mean_ch = blockproc(subchannel, [8 8], fun1);
fun2 = @(block_struct) var(subchannel(:));
variance = blockproc(subchannel, [8 8], fun2);
end
When I run this for, say the red channel of my image(in tiff format), I get a matrix of all same values. When I try to do a scatterplot by reshaping these values I get a single value. I believe the function is only running over a single block hence the single value, but I am supposed to use blockproc as a sliding window operator to calculate the sample mean and variance of each 8x8 block. How can achieve the right results?
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 13 de Dic. de 2021
To get the mean in a sliding window that slides over one pixel at a time:
windowWidth = 3; % Whatever...
kernel = ones(windowWidth) / windowWidth^2;
blurredImage = imfilter(grayImage, kernel);
To get the standard deviation, use stdfilt():
windowWidth = 3; % Whatever...
kernel = ones(windowWidth);
sdImage = stdfilt(grayImage, kernel);
% Square to get variance
varImage = double(sdImage) .^ 2;
Categorías
Más información sobre Neighborhood and Block Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!