imfreehand .createMask for single drawn line instead of region
7 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!