Message Boards Message Boards

0
|
6368 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Extract the boundary points of an image using Wolfram Mathematica?

Posted 6 years ago

Hi, Currently, I am dealing with problems related to images. My intention is to convert an image to binary image and extract the boundary outline of the image to get the coordinates of the boundary image. Through Wolfram Mathematica, we can use the built-in function "binarize" to convert the image to binary image. Further steps to extract the boundary points through Wolfram Mathematica built-in function is not applicable. Is there any built-in function exist to extract the boundary outline points? For my concern, there is a "corner detection" but I could not find the built-in function for binary image outline extraction? Is there any way to extract the binary outline using Wolfram Mathematica? Here is an example of what I want to extract

Original

enter image description here

Extracted Boundary image

enter image description here

I want to get the boundary points and image as above. Can anyone help me?

Thank you in advance for your time

POSTED BY: Nur Soffiah
4 Replies

Hi Soffiah,

regarding the original image you posted one cannot do more than Sander did. But I guess this is not what is wanted in general: In general - and most likely in your case - one starts using a DICOM image from a CT scanner and wants to get the coordinates of the respective pixels in terms of the CTs coordinate system. So I am going to show a simple example on this:

My original DICOM image (see attachment) I am using below looks like this:

enter image description here

The code:

ClearAll["Global`*"]

(* import data and DICOM header: *)
{{dataRaw}, dcmHdr} = Import[FileNameJoin[{NotebookDirectory[], "CT_img.dcm"}], {{"Data", "MetaInformation"}}];

rs = "RescaleSlope" /. dcmHdr;
ri = "RescaleIntercept" /. dcmHdr;
(* rescaling data (HU i.e."Hounsfield" values) according to DICOM-header: *)
dataHU = dataRaw rs + ri;
(* get image position and pixel spacing *)
{x0Pos, y0Pos, zPos} = "ImagePosition" /. dcmHdr;
pixSpacg = "PixelSpacing" /. dcmHdr;

dataHUimg0 = Image[dataHU];
(* cut all values below 800 HU (e.g. for bones): *)
dataHUimg1 = Closing[Binarize[dataHUimg0, 800], 2];
(* and calculate borders: *)
bbImg = Thinning@Binarize@GradientFilter[dataHUimg1, 1];
(* get pixels: *)
ptsImg = PixelValuePositions[Binarize@bbImg, 1] - 1;
(* calculate true position [mm]: *)
ptsMetric = (pixSpacg # + {x0Pos, y0Pos}) & /@ ptsImg;

Graphics[{Blue, PointSize[.005], Point[ptsMetric]}, Frame -> True, AspectRatio -> Automatic, GridLines -> Automatic, FrameLabel -> {"mm", "mm"}]

The result is:

enter image description here

Maybe you find that interesting/helpful, regards -- Henrik

Attachments:
POSTED BY: Henrik Schachner
Posted 6 years ago

Thanks a lot Henrik, it is very helpful and interesting. I am able to extract the boundary of the Dicom Format image.

POSTED BY: Nur Soffiah

With img being the top image you can try things like:

Binarize[img, 0.95]
DeleteSmallComponents[%]
ColorNegate[DeleteSmallComponents[ColorNegate[%]]]
MorphologicalPerimeter[%]
ComponentMeasurements[%, "Contours"]
POSTED BY: Sander Huisman
Posted 6 years ago

Thanks so much for helping me with this.

POSTED BY: Nur Soffiah
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract