binary image mean and SD
显示 更早的评论
Hello;
I need to calculate the mean and SD of a binary image and the result should to be as the following: a sample result: 1: mean: 78.31 stdev: 12.81 2: mean: 99.05 stdev: 16.01 3: mean: 124.69 stdev: 20.45 4: mean: 92.47 stdev: 15.31 5: mean: 139.44 stdev: 22.83 6: mean: 113.05 stdev: 18.61
this is the first part that I did and for the 2nd part i couldnt :/

回答(4 个)
chitresh
2013-12-15
0 个投票
input = imread('Image_file_name');
binary = im2bw(input);
mean = mean2(binary);
std = std2(binary);
Image Analyst
2013-12-15
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in a gray scale demo image.
folder = 'C:\Users\Amal\Documents\Temporary';
baseFileName = 'phantom.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', 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);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 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')
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(grayLevels, pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
meanImage = imfilter(grayImage, ones(9)/81);
% Display the image.
subplot(2, 2, 3);
imshow(meanImage, []);
title('Mean Image', 'FontSize', fontSize);
hp = impixelinfo();
set(hp,'Units', 'Normalized', 'Position',[.8 .98 .300 .20]);
% Threshold to find spots.
binaryImage = meanImage < 150;
% Clean up small bits
binaryImage = bwareaopen(binaryImage, 1000);
% Remove border
binaryImage = imclearborder(binaryImage);
% Display the image.
subplot(2, 2, 4);
imshow(binaryImage, []);
% Label the image
[labeledImage, numberOfSpots] = bwlabel(binaryImage);
% Measure the intensities
measurements = regionprops(labeledImage, grayImage, 'MeanIntensity', 'Centroid');
allIntensities = [measurements.MeanIntensity]
% Label them on image
for spot = 1 : numberOfSpots
theLabel = sprintf('Spot %d = %.2f', spot, allIntensities(spot));
x = measurements(spot).Centroid(1);
y = measurements(spot).Centroid(2);
text(x, y, theLabel, 'Color', 'r', 'FontWeight', 'Bold', 'FontSize', 12);
end
类别
在 帮助中心 和 File Exchange 中查找有关 Explore and Edit Images with Image Viewer App 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!