Azzera filtri
Azzera filtri

I want to freehand draw on an image and crop everything inside and outside of where I drew.

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Image Analyst
Image Analyst il 10 Lug 2018
See attached demo that does this.
  3 Commenti
Image Analyst
Image Analyst il 11 Lug 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.
Serena Tenhumberg
Serena Tenhumberg il 11 Lug 2018
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by