MATLAB Answers

Selection of roi for multiple images

조회 수: 64(최근 30일)
swati mane
swati mane 17 Dec 2019
댓글: swati mane 19 Dec 2019
I have 50 images in one folder. For one image I can select roi by clicking the mouse but now i need automatic selection of roi for multiple images.How to do this ?

  댓글 수: 0

로그인 to comment.

채택된 답변

Rik
Rik 17 Dec 2019
If you want to apply the same ROI to all images: export the ROI as a logical array.
If you want to select a different ROI for each image, generate the list of file names with dir() and loop through the elements.

  댓글 수: 5

표시 이전 댓글 수: 2
swati mane
swati mane 18 Dec 2019
To select roi , I have to click by mouse .I want the parallelogram shaped roi for my project.
Thanks in advance.
This code I am using for the selection of ROI.(numFiles=50)
%Selection of ROI
for m=1:1:numFiles;
a=imread(imgFiles(m).name);% read RGB image (frame no. 1)
imshow(a);
%Selection of ROI
[r c]=ginput(4);
BW=roipoly(a,r,c);
figure;imshow(BW);
ROIArea = bwarea(BW);
[R C]=size(BW);
for i=1:R
for j=1:C
if BW(i,j)==1
Out(i,j)=a(i,j);
else
Out(i,j)=0;
end
end
end
figure;imshow(Out,[]);title('Output Image');
Rik
Rik 18 Dec 2019
The point is to create the ROI only once. Something like the code below should be easy to adapt to your needs.
numFiles=numel(imgFiles);
for m=1:numFiles
a=imread(imgFiles(m).name);% read RGB image (frame no. 1)
if m==1
%generate ROI for first image
figure(1),clf(1)
imshow(a);
%Selection of ROI
[r,c]=ginput(4);
ROI=roipoly(a,r,c);
%ROI is a 2D binary mask
ROI_RGB=repmat(ROI,1,1,3);
end
Out=a;
Out(~ROI_RGB)=0;%set all pixels outside the mask to 0
figure(m),clf(m)
imshow(Out,[])
title(sprintf('Output Image (%d)',m))
end
swati mane
swati mane 19 Dec 2019
Thank you very much !!!

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by