binary image mean and SD

2 visualizaciones (últimos 30 días)
Amal
Amal el 15 de Dic. de 2013
Respondida: Image Analyst el 15 de Dic. de 2013
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 :/

Respuestas (4)

Amal
Amal el 15 de Dic. de 2013
img=imread('phantom.png'); imshow(img); x_ray=im2bw(img,0.65); imshow(x_ray); v=(~x_ray); imshow(v); se=strel('disk',10); xray=imopen(v,se); figure; imshow(xray); [l,num]=bwlabel(xray,4);
% the first part

chitresh
chitresh el 15 de Dic. de 2013
input = imread('Image_file_name');
binary = im2bw(input);
mean = mean2(binary);
std = std2(binary);
  1 comentario
Amal
Amal el 15 de Dic. de 2013
thanx for ur answer when I tried ur way this is was the results: mean
mean =
0.1598
>> SD
SD =
0.3665
while I need the mean and the Sd for each dot in the image and the result should to be as:
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
thanx

Iniciar sesión para comentar.


Amal
Amal el 15 de Dic. de 2013
the lecturer told me that the answer should me similar to that rand('seed', 123456789); F = rand(100, 100); c = (F>=0.5) ; v = logical (c); n = F(v); F=mean (n)
I tried a lot but i couldnt figure the solution... can any one help??

Image Analyst
Image Analyst el 15 de Dic. de 2013
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

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by