Add a margin of desired thickness around the edge of an image
2 views (last 30 days)
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
0 Comments
Accepted Answer
Image Analyst
on 6 Feb 2013
There is a bwconvhull() function you know. You don't have to use the inefficient method of find() and convhull().
I don't know what you want to do. Do you simply want to plot a thick line in the overlay? Or do you want to enlarge the ROI defined by your convex hull? If it's the latter, you could use imdilate() on the convex hull image to enlarge the blobs.
0 Comments
More Answers (1)
Nina
on 6 Feb 2013
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!