Segmentation not working on Dicom images

This is related to a previous question I asked before.
I want to manually segment tumors from Dicom images. I tried the code below but I get a greyish image.
I=dicomread('IMG-0012-00219.dcm');
metadata = dicominfo('IMG-0012-00219.dcm');
WC = metadata.WindowCenter; % original [40; 40]
WW = metadata.WindowWidth;
figure, imshow(I,[WC(1)-WW(1), WC(1)+WW(1)]);
h = drawfreehand; %draw something
M = ~h.createMask();
I(M) = 0;
imshow(I,[WC(1)-WW(1), WC(1)+WW(1)]);
imwrite(im2double(I),'Image3.png','mode','loseless')
The segmentation works fine, but the image is greyish which is not desirable. Any suggestions would be appreciated.

5 commentaires

Simon Chan
Simon Chan le 22 Nov 2022
You may use a new Window Level and W8ndow Width instead of the default one from the original dicom image. The default one is for the entire image viewing purpose which may not be optimum for the segmented image.
DGM
DGM le 22 Nov 2022
Modifié(e) : DGM le 22 Nov 2022
In addition to what Simon mentioned, I don't know if you're running into a scenario where zero is brighter than the darkest pixels in your ROI. Depending on what you have for WindowWidth, zero may be brighter than WC(1)-WW(1).
Warid Islam
Warid Islam le 28 Nov 2022
Hi @DGM,
How do I change the Window Width in order to put zero as brigther than WC(1)-WW(1).
You either have to shift/rescale all the image data, or you simply don't use zero for the fill color. It depends if you want to preserve the relative scale and value of the image data.
If you don't care about the absolute scale of the data and all you want is an image for visualization purposes, you might be able to just do something like this:
% ...
h = drawfreehand; %draw something
M = ~h.createMask();
% create a copy and normalize it WRT the window metadata
outpict = mat2gray(I,[WC(1)-WW(1), WC(1)+WW(1)]); % unit-scale double
outpict(M) = 0; % fill background region with black
% display and write
imshow(outpict);
imwrite(outpict,'Image3.png','mode','loseless')
Warid Islam
Warid Islam le 29 Nov 2022
Hi @DGM,
It worked. Thank you very much.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 22 Nov 2022
I'm not sure what you mean by the image looks greyish. It looks like the masked blob in the middle has the full dynamic range. Do you just want to make the gray background be black? Like (untested)
grayMask = grayImage == grayImage(1,1);
grayMask = bwareafilt(grayMask, 1);
grayImage(grayMask) = 0;
imshow(grayImage, []);

2 commentaires

Warid Islam
Warid Islam le 28 Nov 2022
I tried the above code. But I am getting the following image.
The resulting image should look something like below. The reason I am not using the result below because that is the result of segmenting the original image which was converted to png file and then segmentation was performed. What I want now is to apply the segmentation on the original dicom file and obtaining the segmentation result as below.
Image Analyst
Image Analyst le 28 Nov 2022
Please attach the original gray scale image and the segmented (binary) image (the mask image).

Connectez-vous pour commenter.

Catégories

En savoir plus sur DICOM Format dans Centre d'aide et File Exchange

Produits

Version

R2021a

Commenté :

le 29 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by