Info

This question is closed. Reopen it to edit or answer.

I want each object space

1 view (last 30 days)
jojoe aloha
jojoe aloha on 30 Jan 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Help me please.
img=rgb2gray(imread('E:\image\nok.jpg'));
subplot(3,3,1),imshow(img);
buf2=imadjust(img,[0.2 0.8],[0 1],0.8);
subplot(3,3,2),imshow(buf2);title('Gray-level tranform');
oup=medfilt2(buf2);
disp=mat2gray(oup);
%threshold=graythresh(img);
[junk threshold]=edge(disp,'sobel');
fudgeFactor=.5;
BWs=edge(img,'sobel',threshold*fudgeFactor);
subplot(3,3,3),imshow(BWs);
se90=strel('line',9,90);
se0=strel('line',9,0);
BWsdil=imdilate(BWs,[se90 se0]);
subplot(3,3,4),imshow(BWsdil);
BWdfill=imfill(BWsdil,'holes');
subplot(3,3,5),imshow(BWdfill);
BWnobord=imclearborder(BWdfill,4);
subplot(3,3,6),imshow(BWnobord);
bw=bwareaopen(BWnobord,200);
se=strel('disk',9);
bw=imopen(bw,se);
%bw=imfill(bw,'holes');
subplot(3,3,7),imshow(bw);title('Open');
[B,L] = bwboundaries(bw,'noholes');
subplot(3,3,8),imshow(label2rgb(L,@jet,[.5 .5 .5]));
hold on;
for k = 1 :length(B)
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'w','LineWidth',2)
end

Answers (2)

Walter Roberson
Walter Roberson on 30 Jan 2014
Once you have the objects labeled, use regionprops('Area') on the label matrix.

Image Analyst
Image Analyst on 30 Jan 2014
I don't know what you mean by object space. If you want the area of each region, you can look at my Image Segmentation Tutorial where it goes over that in well commented detail. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
In short
measurements = regionprops(bw, 'Area');
allAreas = [measurements.Area]; % Get all areas into an array
[sortedAreas, sortOrder] = sort(allAreas, 'descend'); % Option, if you want to sort them.

Tags

Community Treasure Hunt

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

Start Hunting!