segment an image into portions..

i have a image, please can someone help me, to segment it into regions
i applied otsu threshold binarization to the image, and got a binary image,
from the binary image is it possible to get the top, bottom, left, right and center regions as a box region...
bw = im2bw(Gray, graythresh(Gray));

2 Comments

Do you want to do this based on the color (or grayscale) information or just based on the location?
color or gray does not matter, sir... is it possible to get such portions....

Sign in to comment.

 Accepted Answer

Image Analyst
Image Analyst on 22 Apr 2015
Find the centers of each zone automatically. The centroid will be at the center - use regionprops(). The others you can get by using imerode on the binary image to shrink the mask, then take the north, south, east and west pixels. Use find() for that. Now you have the centers of each zone. Then use voronoi() to get the zones themselves.

6 Comments

sir, do you have any example demo, of the above.... or any link demonstrating the same...
Sorry, no I don't. But you've been using MATLAB quite a while now. I know you know how to threshold images, how to use regionprops() to find the centroid, how to call imerode(), and how to use find() to find the top, right, left, and bottom pixels at the centroid of the image. Give it a try and post your code.
iImage = imread('myimage.jpg');
figure, subplot(2,2,1), imshow(iImage);
Gray = rgb2gray(iImage);
subplot(2,2,2), imshow(Gray); hold on;
bw = im2bw(Gray, graythresh(Gray));
subplot(2,2,3), imshow(bw);
se = strel('disk',4,0);
bw = imerode(bw,se);
subplot(2,2,4), imshow(bw);
% As there were many blobs i took the blob with largest area.
[labeledImage, numberOfBlobs] = bwlabel(bw);
blobMeasurements = regionprops(labeledImage, 'area');
allAreas = [blobMeasurements.Area];
[sortedAreas, sortIndexes] = sort(allAreas, 'descend');
biggestBlob = ismember(labeledImage, sortIndexes(1,1));
blobMeasurements = regionprops(biggestBlob, 'BoundingBox');
boundingBox = blobMeasurements.BoundingBox;
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
subplot(2,2,4), imshow(bw); hold on;
plot(verticesX, verticesY, 'r-', 'LineWidth', 2);
but it is not coming correctly... the left corner of the image is coming as the blob with largest area... sir, what should i do to get the whole tongue image...
You need to also ask regionprops() for the Centroid. Then get the centroid and round it to the nearest integer so we can extract a vertical line and horizontal line through the binary image. Then you can use find on each of those. Something like
blobMeasurements = regionprops(biggestBlob, 'BoundingBox', 'Centroid');
centroid = blobMeasurements.Centroid;
centroidX = centroid(1);
centroidY = centroid(2);
centerLine = bw(centroidX, :);
leftColumn = find(centerLine, 1, 'first');
rightColumn = find(centerLine, 1, 'last');
centerColumn = bw(:, centroidY);
topLine = find(centerColumn, 1, 'first');
bottomLine = find(centerColumn, 1, 'last');
Now construct the coordinates and call voronoi().
sir i didnt get... how to use voronoi..
I will have not much time this weekend. I'm leaving this afternoon to go camping for the weekend, so hopefully you can get it done without me. I haven't used voronoi much lately so I'd have to figure it out just like you, from the help. But I know that it divides an image up into zones based on equidistant lines between points. I think there are examples so hopefully you can figure it out without me.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!