필터 지우기
필터 지우기

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

채택된 답변

Image Analyst
Image Analyst 2018년 7월 10일
See attached demo that does this.
  댓글 수: 3
Image Analyst
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.
Serena Tenhumberg
Serena Tenhumberg 2018년 7월 11일
Yes, I figured that out pretty easily. My next dilemma is to have the final image in color. When I edit the code to be in color, the inside mask ends up being a teal color or a red color depending on what I write. Do you know why this would be happening? I tried using a png file as well, with no luck. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by