I want to freehand draw on an image and crop everything inside and outside of where I drew.
3 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191783/image.jpeg)
0 个评论
采纳的回答
Image Analyst
2018-7-10
See attached demo that does this.
3 个评论
Image Analyst
2018-7-11
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!