How to display all selected region in the one figure?

N = 5 ;
I = imread('13170.jpg');
iwant = cell(N,1) ;
for i = 1:N
im = imshow(I);
e = imellipse(gca);% now pick ROI
setColor(e, 'red');
position = wait(e);
BW = createMask(e,im);% get BW mask for that ROI
BW(:,:,2) = BW;
BW(:,:,3) = BW(:,:,1);
ROI = I;
ROI(BW == 0) = 255;
iwant{i} = ROI ;
end
for i = 1:N
figure
imshow(iwant{i},'Border','tight');
end

 Risposta accettata

Here is a sample using subplot.
figure,
for i = 1:N
subplot(2,3,i),imshow(iwant{i});
end

7 Commenti

Thank for helping me. But how to merge all the region into one figure? like the photo below
Here it is.
Iout = uint8(zeros(236,364,3));
for i = 1:N
I= iwant{i};
idx= (I == 255);
I(idx) = 0;
Iout= Iout + I;
end
Iout(Iout == 0) = 255;
figure,imshow(Iout);
If you want to avoid overlap, you can subtract overlap area.
BW2out = BW2 - (BW & BW2);
where BW2,BW are mask for images.
Great, it is useful for me. Thank for helping me, wish you have a nice day.
Mei Synn Tan
Mei Synn Tan il 3 Feb 2017
Modificato: Mei Synn Tan il 3 Feb 2017
Dear Takuji Fukumoto, the result showing the content of selected part is not clear, how to avoid it? How to subtract overlap area? Thanks
I think you merged 2 images. Could you show them?
Dear Takuji Fukumoto, here it is. the result showing the content of selected part is not clear, how to avoid it? how to avoid it? Thanks and have a nice day.
N = 2 ;
I = imread('13100.jpg');
iwant = cell(N,1) ;
for i = 1:N
im = imshow(I);
e = imellipse(gca);% now pick ROI
setColor(e, 'red');
position = wait(e);
BW = createMask(e,im);% get BW mask for that ROI
BW(:,:,2) = BW;
BW(:,:,3) = BW(:,:,1);
ROI = I;
ROI(BW == 0) = 255;
iwant{i} = ROI ;
end
Iout = uint8(zeros(364,236,3));
for i = 1:N
I= iwant{i};
idx= (I == 255);
I(idx) = 0;
Iout= Iout + I;
end
Iout(Iout == 0) = 255;
figure,imshow(Iout,'Border','tight');
Is the answer from Image Analyst acceptable for you? If you need more help, let me know.

Accedi per commentare.

Più risposte (2)

Mei, try the attached for a more memory efficient way of doing it. Don't be afraid, there are actually fewer lines than you and Takuja were using if you boil it down to the essentials. It's just longer because I put in tons of comments and some fancy display stuff to show your progress while drawing. I just mask the image at the end with the final mask. If you want, you can get updated images in the lower right that update after every ellipse so it would show 1 ellipse, then 2, then 3, etc.
Takuji: Don't make iwant a cell array. Make it your final image. Just paste in the ellipses from the source image. Adapt my attached copy and paste demo.

2 Commenti

Thank for answer my question. Hope Takuji Fukumoto can help me. Thanks and have a nice day
Image Analyst
Image Analyst il 4 Feb 2017
Modificato: Image Analyst il 4 Feb 2017
Does that mean that you don't want me to help? I have a much better way than you or Takuja - I just didn't have time yesterday. It's in my second answer - look for it if you're interested.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by