binary image mean and SD

조회 수: 2 (최근 30일)
Amal
Amal 2013년 12월 15일
답변: Image Analyst 2013년 12월 15일
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개)

Amal
Amal 2013년 12월 15일
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 2013년 12월 15일
input = imread('Image_file_name');
binary = im2bw(input);
mean = mean2(binary);
std = std2(binary);
  댓글 수: 1
Amal
Amal 2013년 12월 15일
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

댓글을 달려면 로그인하십시오.


Amal
Amal 2013년 12월 15일
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 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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by