Add a margin of desired thickness around the edge of an image
Show older comments
I have drawn an ROI, made a mask of it, used convex hull and shaded this in. I then want to add a margin/border to this shape of a desired thickness that starts at the edge of the plotted xy convex hull coordinates (in pixels preferably). I am using DICOM images and want to draw around a lesion then add a safety margin to it for excision.
I've searched for a while to find a suitable function and the nearest I have gotten to a solution is to plot the convex hull xy points with a line thickness of however many pixels - this line starts to have 'cracks' in once it is thicker than a few mm and is centered on the plot coordinates rather than starting at the edge. Here is what I did from creating the convex hull:
bw = bwconvhull(mask);
%user enters desired margin thickess
Mar = inputdlg('Enter desired margin width in mm');
MAR =str2double(Mar);
%Some math to convert pixel to mm
n = MAR / pixel;
m = (n ./ pixel)*2;
%Fill convex hull and plot line with width m
[y, x] = find(bw);
k = convhull(x, y);
hold on
plot(x, y, 'c.');
plot(x(k), y(k), 'c', 'LineWidth', m);
hold off
Accepted Answer
More Answers (1)
Nina
on 6 Feb 2013
0 votes
2 Comments
Image Analyst
on 6 Feb 2013
You're finding every pixel in the mask then plotting a dot there. That's strange. I don't know why you don't just use plot() to plot the outline, or use patch() to overlay a colored patch over the image.
Nina
on 8 Feb 2013
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!