Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
region indication

Subject: region indication

From: valli

Date: 2 Nov, 2010 05:32:02

Message: 1 of 3

i have a grey scale image..i need to indicate the particular regions in the image. can any one help me?
                                thanking u

Subject: region indication

From: Sean

Date: 2 Nov, 2010 13:33:04

Message: 2 of 3

"valli " <vallinayagam2007@gmail.com> wrote in message <iao7oi$dpi$1@fred.mathworks.com>...
> i have a grey scale image..i need to indicate the particular regions in the image. can any one help me?
> thanking u

Well what makes a particular region special enough to indicate? Figure out was those criteria are and then do what you will with them

Subject: region indication

From: ImageAnalyst

Date: 2 Nov, 2010 15:04:43

Message: 3 of 3

On Nov 2, 1:32 am, "valli " <vallinayagam2...@gmail.com> wrote:
> i have a grey scale image..i need to indicate the particular regions in the image. can any one help me?
> thanking u

----------------------------------------------------------
valli :
Where did you post your image, so we can look at it and give
suggestions? If you can use thresholding, here's an example:
http://www.mathworks.com/matlabcentral/fileexchange/25157

If you want to freehand draw the region, here is a demo:
(BE SURE TO JOIN ANY LONG LINES THAT GOT SPLIT INTO TWO BY THE
NEWSREADER)
-ImageAnalyst

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Read in standard MATLAB gray scale demo image.
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
message = sprintf('Left click and hold to begin drawing.\nSimply lift
the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand();

% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
% Display the freehand mask.
subplot(2, 2, 2);
imshow(binaryImage);
title('Binary mask of the region', 'FontSize', fontSize);

% Calculate the area, in pixels, that they drew.
numberOfPixels1 = sum(binaryImage(:))
% Another way to calculate it that takes fractional pixels into
account.
numberOfPixels2 = bwarea(binaryImage)

% Get coordinates of the boundary of the freehand drawn region.
structBoundaries = bwboundaries(binaryImage);
xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates.
x = xy(:, 2); % Columns.
y = xy(:, 1); % Rows.
subplot(2, 2, 1); % Plot over original image.
hold on; % Don't blow away the image.
plot(x, y, 'LineWidth', 2);

% Burn line into image by setting it to 255 wherever the mask is true.
burnedImage = grayImage;
burnedImage(binaryImage) = 255;
% Display the image with the mask "burned in."
subplot(2, 2, 3);
imshow(burnedImage);
title('New image with mask burned into image', 'FontSize', fontSize);

% Mask the image and display it.
% Will keep only the part of the image that's inside the mask, zero
outside mask.
maskedImage = grayImage;
maskedImage(~binaryImage) = 0;
subplot(2, 2, 4);
imshow(maskedImage);
title('Masked Image', 'FontSize', fontSize);

% Calculate the mean
meanGL = mean(maskedImage(binaryImage));

% Report results.
message = sprintf('Mean value within drawn area = %.3f\nNumber of
pixels = %d\nArea in pixels = %.2f', ...
    meanGL, numberOfPixels1, numberOfPixels2);
msgbox(message);

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us