average local variance
조회 수: 11 (최근 30일)
이전 댓글 표시
Hi, I need to compute the diagonal error weight matrix (W), where W(i,i) measure the average local variance of pixels with gray level i. Can u please help me regarding this. i will be grateful.
댓글 수: 1
Oleg Komarov
2012년 3월 3일
Not enough info: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
채택된 답변
Image Analyst
2012년 3월 3일
Again, I'm not sure what this means or if it is really what you want but I think it's what you described.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Calculate the standard deviation image.
sdImage = stdfilt(grayImage);
% Display the image.
subplot(2, 3, 2);
imshow(sdImage, []);
title('Std. Dev. Image', 'FontSize', fontSize);
% Calculate the variance image.
varianceImage = sdImage .^2;
% Display the image.
subplot(2, 3, 3);
imshow(varianceImage, []);
title('Variance Image', 'FontSize', fontSize);
% Calculate the mean of the variance image in a 3x3 region.
% Basically this is a blurred version of it.
meanVarianceImage = conv2(varianceImage, ones(3)/9);
% Display the image.
subplot(2, 3, 4);
imshow(meanVarianceImage, []);
title('Mean Variance Image', 'FontSize', fontSize);
for gl = 0:255
% Find pixels in the original image with this gray level.
matchingIndexes = (grayImage == gl);
% Get the mean of only those pixels from the mean variance image.
W(gl+1) = mean(meanVarianceImage(matchingIndexes));
end
% Plot W
subplot(2, 3, 5);
plot(W);
grid on;
title('Plot of W', 'FontSize', fontSize);
xlabel('Gray Level', 'FontSize', fontSize);
추가 답변 (1개)
Image Analyst
2012년 3월 3일
I'm not sure what W is. But you can use stdfilt() to get the st.dev. in a local window of an image. Square it to get the variance. If you want the average of the 9 variances of the 9 pixels in a 3x3 neighborhood, then you can use imfilter() or conv2() with a kernel of ones(3)/9. Then you need to go through each gray level, extracting that mean variance, something like (maybe??? untested)
for gl = 0:255
% Find pixels in the original image with this gray level.
matchingIndexes = (imageArray == gl);
% Get the mean of only those pixels from the mean variance image.
W(gl+1) = mean(meanVarianceImage(matchingIndexes ));
end
댓글 수: 2
Image Analyst
2012년 3월 3일
No, it's not all zero - you're just not using [] to display in with imshow. See my other answer for a more complete demo.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!