Message Boards Message Boards

0
|
6449 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
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