imfreehand .createMask for single drawn line instead of region

7 views (last 30 days)
Hi, Im wondering if theres a way to modify the demo you've posted around using imfreehand() to use the createMask function to apply to only a single free hand drawn line rather than the entire closed region that line could form. I have been able to successfully make the line using:
hFH = imfreehand();
setClosed(hFH,0);
Then:
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
% Display the freehand mask.
subplot(2, 2, 2);
imshow(binaryImage);
This produces a closed shape from my drawn free hand line in Binary, however I want to create a mask for just the line I drew, not the resulting closed shape. Anyway to do this?

Answers (1)

Image Analyst
Image Analyst on 14 Jan 2014
Edited: Image Analyst on 14 Jan 2014
Evidently you haven't see one of my demos, which does what you request. See attached demo in blue text below this snippet.
hFH = imfreehand();
% Get the xy coordinates of where they drew.
xy = hFH.getPosition
% get rid of imfreehand remnant.
delete(hFH);
% Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
xCoordinates = xy(:, 1);
yCoordinates = xy(:, 2);
plot(xCoordinates, yCoordinates, 'ro', 'LineWidth', 2, 'MarkerSize', 10);
  2 Comments
A
A on 14 Jan 2014
Sorry I missed that demo and thanks for the quick reply. I'm a bit confused about how I could use this to create a Binary Mask of the line drawn. I recently starting learning MatLab but my understanding of .createMask is that it requires the imfreehand object to be passed to it (i.e. binary image = h.createMask() where h= imfreehand()) With this script the freehand object is deleted after its position is taken as x and y coordinates so how would you use that information to generate the binary mask?
Image Analyst
Image Analyst on 14 Jan 2014
This gives you coordinates of the line you drew. If you want a binary mask from that, just create one:
binaryImage = false(rows, columns);
for k = 1 : length(x)
binaryImage(int32(y(k)), int32(x(k))) = true;
end

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!