Hello, i have the following code, is there any way to rewrite it to create a loop so that it subtracts the 1st photo from 2nd until the 69th and then create a graph as it at the with all the boundaries ?
Thank you very much for the Help guys!
pic01=imread("1.tiff");
pic1=im2gray(pic01);
i=1;
%for i=1:69;
pic050=imread("69.tiff");
pic50=im2gray(pic050);
newpicture=imsubtract(pic01,pic050);
%imshow(newpicture)
level = graythresh(newpicture);
level = 0.1405;
newbinpic = imbinarize(newpicture,level);
%imshowpair(newpicture,newbinpic,'montage')
newbinpic2=bwpropfilt(newbinpic,'perimeter',1);
%imshowpair(newbinpic2,newpicture,'montage');
boundaries = bwboundaries(newbinpic2);
binaryImage = 0.6< newbinpic2 & newbinpic2<1;
hold on
for k=1:length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:,2);
y = thisBoundary(:,1);
plot(x,y,'r-','Linewidth',2);
end
grid on

 採用された回答

yanqi liu
yanqi liu 2021 年 10 月 12 日

0 投票

pic01=imread("1.tiff");
pic1=im2gray(pic01);
i=1;
boundaries=[];
for i=1:69;
pic050=imread("69.tiff");
pic50=im2gray(pic050);
newpicture=imsubtract(pic01,pic050);
%imshow(newpicture)
level = graythresh(newpicture);
level = 0.1405;
newbinpic = imbinarize(newpicture,level);
%imshowpair(newpicture,newbinpic,'montage')
newbinpic2=bwpropfilt(newbinpic,'perimeter',1);
%imshowpair(newbinpic2,newpicture,'montage');
boundariesi = bwboundaries(newbinpic2);
boundaries=[boundaries; boundariesi];
binaryImage = 0.6< newbinpic2 & newbinpic2<1;
end
figure; imshow(pic01);
hold on
for k=1:length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:,2);
y = thisBoundary(:,1);
plot(x,y,'r-','Linewidth',2);
end
grid on

その他の回答 (1 件)

Matt J
Matt J 2021 年 10 月 11 日

0 投票

It is possible:
for i=1:69;
pic=im2gray( imread(i+".tiff") );
...
end

4 件のコメント

Alex Perrakis
Alex Perrakis 2021 年 10 月 11 日
But will it produce a graph with all the boundaries of the images it read?
Matt J
Matt J 2021 年 10 月 11 日
If you put the appropriate code in the loop it will.
Alex Perrakis
Alex Perrakis 2021 年 10 月 11 日
that's what i was asking :) i will have to create a pic variable which runs with the loop right?
Matt J
Matt J 2021 年 10 月 11 日
Yes, I've shown you how to create a looping pic variable. The rest of the code you seem to already have in your original post.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 10 月 11 日

回答済み:

2021 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by