Hello everyone.I would like to ask you how to extract the data of a local area of a picture. The code I wrote is shown below. Please help me correct the mistakes. Thank you all.
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623803/image.jpeg)
BW21=imread('m1.jpg');
% stats = regionprops(BW21,'Area','Centroid');%binaryImage
%
% %props = regionprops(BW21, 'Perimeter');%binaryImage
[labeledImage, numRegions] = bwlabel(BW21);%binaryImage
props = regionprops(labeledImage, 'Area','Centroid','Perimeter');
% Compute all the areas.
allAreas = [props.Area];
% Display each blob in its own figure.
for k = 1 : numRegions
thisRegion = ismember(labeledImage, k);
figure;
imshow(thisRegion);
drawnow;
end
%%%Data extraction of the first region on the image
data=imbinarize(BW21);%'image.jpeg'
result=edge(data);
figure,imshow(result);
[r,c]=find(result==1);
figure,plot(c,r,'.');
%%%Data extraction for the first area
for i=1:1:912
for j=1:1:1312
if BW31(i,j)~=1
BW31(i,j)=0;
end
end
end
x = linspace(1,912,912)';
y = linspace(1,1312,1312)';
contourf(y, x, BW31 ,20);
colorbar;
xlabel('x');
ylabel('y');
axis equal
data=imbinarize(BW31);%'image.jpeg'
result=edge(data);
figure,imshow(result);
[r,c]=find(result==1);
figure,plot(c,r,'.');
%
% Data extraction for the second area
%
BW32=bwlabel(BW21);
for i1=1:1:912
for j1=1:1:1312
if BW32(i1,j1)~=1
BW32(i1,j1)=0;
end
end
end
x1= linspace(2,912,912)';
y1 = linspace(2,1312,1312)';
contourf(y1, x1, BW32 ,20);
colorbar;
xlabel('x1');
ylabel('y1');
axis equal
data1=imbinarize(BW32);%'image.jpeg'
result1=edge(data1);
figure,imshow(result1);
[r1,c1]=find(result1==1);
figure,plot(c1,r1,'.');
...
%
0 个评论
回答(3 个)
Sulaymon Eshkabilov
2021-5-20
Is that what you are trying to get?
D = imread('BW.jpeg');
MYdata=imbinarize(D);
figure(1)
imshow(MYdata);
R=edge(MYdata);
figure,imshow(R);
[Edge,C]=find(R==1);
figure(2)
plot(C,Edge,'k.'), title('Separated local area pictures')
Sulaymon Eshkabilov
2021-5-20
Maybe here you can find some good help:
https://www.mathworks.com/matlabcentral/answers/76528-measurement-in-images-image-analysis?s_tid=srchtitle
Image Analyst
2021-5-20
You say "My idea is to extract the data from the first area. The second, the third, and the area behind it don't matter." By "area" I assume you mean "region". I have no idea what "data" means. You can get the area, the cropped region, individual uncropped blobs using ismember(), and lots of other stuff from regionprops().
But you have
% Compute all the areas.
allAreas = [props.Area];
so you're getting all the areas of all the blobs, if "area" is what you meant by "data". Otherwise, explain what "data" means to you. And define what you mean by "first" since blobs have varying size and are at verying locations.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visual Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!