I want to freehand draw on an image and crop everything inside and outside of where I drew.
3 views (last 30 days)
Show older comments
Serena Tenhumberg
on 10 Jul 2018
Commented: Serena Tenhumberg
on 11 Jul 2018
I wrote a code to freehand draw on a circle to crop out everything inside and outside and it's running through and not giving me any errors but the end result is just 3 white figures.
clc;
clear;
close all;
J=imread('M004L_SI_06_ORO.png'); %specify picture
h_im=imshow(J)
%%Draw contours onto the phase image to isolate the vessel wall.
%You will be prompted to draw for the number of "imfreehand" commands below.
% Draw in this order: lumen, intima, EEL
message_1=sprintf('Draw Lumen');
uiwait(msgbox(message_1));
Lumen = imfreehand(gca,'Closed','True');
message_2=sprintf('Draw Intima');
uiwait(msgbox(message_2));
Intima = imfreehand(gca,'Closed','True');
message_3=sprintf('Draw EEL');
uiwait(msgbox(message_3));
EEL = imfreehand(gca,'Closed','True');
%%Obtain x-y coordinates
Lumenxy=Lumen.getPosition;
Intimaxy=Intima.getPosition;
EELxy=EEL.getPosition;
%%Create a binary image ("mask")
LumenImage =Lumen.createMask();
IntimaImage = Intima.createMask();
if size(EELxy,1) < 20
EELimage = [];
else
EELimage = EEL.createMask();
end
%%Set to "white" (or >255) all positions on the inside (lumen) and outside of the vessel wall
Intimafinal1(IntimaImage == 0) = 999; % Set the outside of contour 1 to zero and inside of contour 2 to zero (leaving only the area in-between the contours)
Intimafinal1(LumenImage == 1) = 999;
if isempty(EELimage) == 0
Efinal2(EELimage == 0) = 999;
Efinal2(IntimaImage == 1) = 999;
end
%%Check final image
figure2 = figure('PaperType','A','Color',[1 1 1],'units','normalized','outerposition',[0 0 1 1]);
hold on;
imshow(Intimafinal1,[0.25 0.4],'InitialMagnification','fit');
if isempty(EELimage) == 0
figure3 = figure('PaperType','A','Color',[1 1 1],'units','normalized','outerposition',[0 0 1 1]);
hold on;
imshow(Efinal2,[0.25 0.4],'InitialMagnification','fit');
hold off;
end
figure
0 Comments
Accepted Answer
Image Analyst
on 10 Jul 2018
See attached demo that does this.
3 Comments
Image Analyst
on 11 Jul 2018
Yes, just call imfreehand twice and create a mask. A true one for the outer ring, and an inner mask that zeros out that part of the outer mask. Easy. Let me know if you can't figure it out.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!