计算在每个像素处保持灰度图像的标准偏差的矩阵(即,X(i,j)保持在行i,列j处的所有图像的灰色像素强度的标准偏差。
我有(或相信我有)灰度的平均图像。我也有颜色的平均图像,但不认为这与此问题相关。我知道标准差需要我通过并总结每个值和平均值之间的差异,但不知道如何到达那里。
% Matrix initialization
setsum1 = zeros(215, 300, 3, 'double');
% Loop through all the image files in one directory and store in the matrix
filelist = dir('set1\*.jpg');
for i=1:length(filelist)
imname = ['\set1\' filelist(i).name];
nextim = imread(imname);
setsum1 = setsum1 + im2double(nextim);
end
% Compute the average image in color
setsum1_rgb = setsum1./length(filelist);
% Compute the average image in grayscale
setsum1_gray = rgb2gray(setsum1_rgb);
% grayscale images’ standard deviation at each pixel
deviation_setsum1_gray = sqrt(sum(power(??? - setsum1_gray, 2)));
解决办法:
您已经计算了平均图像。但是,如果要计算标准偏差,则必须记住所有图像上的所有图像强度。请记住,标准偏差定义为每行和列位置的图像强度之间的平方差之和的平方根,该位置的平均强度除以减去1的图像数量。因此我建议您存储图像为4D矩阵,其中第四维表示每个图像的颜色版本。我们还需要另一个类似的变量,但它将是一个3D矩阵,它将在第三维上存储每个图像的灰度版本。之后,我们可以最终计算每个空间位置的标准偏差。你甚至可以使用std 功能在第三维,所以你甚至不需要使用平均图像,但我假设你必须自己做。
假设你不能使用std,这样的东西会起作用:
% Loop through all the image files in one directory and store in the matrix
filelist = dir('set1\*.jpg');
% Matrix initialization
% New - Make the fourth channel as long as the total number of images
setsum1 = zeros(215, 300, 3, numel(filelist), 'double');
% New - Store the grayscale images too
% Make the third channel as long as the total number of images
setsum1_gray = zeros(215, 300, numel(filelist), 'double');
for i=1:length(filelist)
imname = ['\set1\' filelist(i).name];
nextim = imread(imname);
setsum1(:,:,:,i) = im2double(nextim); % New - Store the image per channel
setsum1_gray(:,:,i) = rgb2gray(setsum1(:,:,:,i)); % New - Grayscale convert the colour image and save it
end
% Compute the average image in grayscale and colour
% Note - I would just use mean if possible
% setsum1_gray_avg = mean(setsum1_gray, 3);
% setsum1_rgb = mean(setsum1, 4);
% ... or
% setsum1_gray_avg = sum(setsum1_gray, 3) / numel(filelist);
% setsum1_rgb = sum(setsum1, 4) / numel(filelist);
setsum1_rgb = zeros(215, 300, 3);
setsum1_gray_avg = zeros(215, 300);
for i = 1 : numel(filelist)
setsum1_rgb = setsum1_rgb + setsum1(:,:,:,i);
setsum1_gray_avg = setsum1_gray_avg + setsum1_gray(:,:,i);
end
setsum1_rgb = setsum1_rgb / numel(filelist);
setsum1_gray_avg = setsum1_gray_avg / numel(filelist);
% Now compute standard deviation for each pixel








暂无数据