Thresholding a CT scan image.

Hello everyone.
I am a university student from Turkey and currently working on detection and clasification of cancerous regions on lung CT scans and i have a major problem at the moment. This is my first question on this community tab so i want to explain my problem very clearly.
In the beginning we have an image sized by 512x512 in DICOM format the first thing i did is converting this image from DICOM to JPG the reason for this is in DICOM format the image has some type of blur when it is converted to JPG that blur goes away after that i added new lines and colums to this image to make it 550x550 so i can create equal square windows sized by 50x50 and after expanding the image i converted it from JPG to grayscale image with rgb2gray command after this point i am starting to thresholding the image and also this is where my problem starts.
My advisor told me to make the windows sit on each other and here is an image to explain it better.
Here each different color represents a different window and the next window is one colum away from the previous window so they can overlap each other with only one colum of difference and after extracting the window we find the T value for the it with following formula
T(i,j) = m(i,j) + k*σ(i,j)
Where m(i,j) and σ(i,j) are the local mean and standard deviation in a particular window around any pixel (i,j), respectively.
After finding the T value i convert the window from gray scale image to binary image with imbinarize but it does not work the code i wrote finds every T value for each window but the result is just a black image and i couldnt find any solution if there is a fundemantal problem with my logic please point it out because i cant find it myself the end result should be an image with only ones and zeros where they represent black and white, for example:
And here is the part of my code where i do all this work that i explained:
%% Thresholding the image.
ImageThresh = zeros(550); % An empty shell for our thresholded image.
k = (-0.2); % A fixed value.
a = 1; % a and c represent the lines and their values change with each loop.
b = 1;
c = 1; % b and d represent the colums and their values change with each loop.
d = 1;
for i = 1:11 % This for loop is for lines the reason it goes from 1 to 11 is because of our image's size is 550x550 and our windows are 50x50 so to get 550 it has to loop for 11 times.
for r = 1:500 % Same mentality with the above for loop but it is for the colums and is a bit different.
T = mean2(image(a:c+49,b:d+49)) + (k*std2(image(a:c+49,b:d+49))); % Here we find the threshold value for each window.
ImageThresh(a:c+49,b:d+49) = imbinarize(image(a:c+49,b:d+49),T); % Here we are converting the image to binary image.
b = b+1;
d = d+1;
if d+49 >= 550 % These four if states are here to not pass the boundries of our image (550x550)
d = 1;
end
if b >= 501
b = 1;
end
end
a = a+1;
c = c+1;
if c+49 >= 550
c = 1;
end
if a >= 501
a = 1;
end
end
figure(2);
imshow(ImageThresh), title('Thresholded image');
axis on;
impixelinfo;
I am only a novice at using MATLAB so if my code looks unprofessional i am sorry and thanks to everyone for their comments in advance.

1 Comment

the first thing i did is converting this image from DICOM to JPG the reason for this is in DICOM format the image has some type of blur when it is converted to JPG that blur goes away
That definitely sounds wrong. JPG is a lossy compression method, so it should only make the original DICOM gray values worse.

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 6 Dec 2021
Before implementing the decomposition into tiles, you should probably just try imbinarize(image,'adaptive'), which does something very similar.

9 Comments

The word "Blur" might be the wrong word to use but in DICOM the image is almost totally gray when it is turned into JPG it becomes something like the image below that is what i was trying to explain in question.
When i started this project the first thing i did is exactly what you said but let me show you why that is not the answer.
Image on the left here is the JPG image and the image on the right is the result of imbinarize(image,'adaptive'), the reason why this does not work is the connection between the chest and the rest of the image, do you see the string looking or tree branch looking things that are touching the chest ? They are the problem here because after this step i will have to use connected component analysis to detect the chest and remove it from the image but with the presence of these tree branch looking things it is imposible to use because they connect the organs and the other parts of the image with the chest, the image i provided in my question is my advisor's own work. There, she did what i tried to explain in my question with that overlapping the strings get removed from the image. After showing her the image i got with imbinarize(image,'adaptive') she told me to do the same thing but it did not work probably because i made a mistake somewhere and after that i wrote my question.
Image on the left here is the JPG image and the image on the right is the result of imbinarize(image,'adaptive')
That's not what I get:
load image;
imshow(imbinarize(A,'adaptive'))
Sir, i tried to get this but i dont understand i get something different and when i try to run your code it gives an error. What is the format of the image that is not corverted to binary is it JPG or gray scale ? Because i can run the imbinarize with the gray scale image but it gives something different:
If i try to run the code without converting the image to gray scale it gives a dimension error and if i convert it and run the code i dont get full white image like yours.
What is the format of the image that is not corverted to binary
It was provided to you in the image.mat file attached to my last comment. I simply downloaded the image you displayed for us and read it into Matlab,
the file i attached here is the image that is converted from DICOM to JPG and here is what i did after seeing your answer:
load LIDC-IDRI-0072-1.dcm.jpg
imshow(imbinarize(A,'adaptive'))
This gives error because obviously there is no 'A' and if i do it like this:
A = imread('LIDC-IDRI-0072-1.dcm.jpg');
A = rgb2gray(A);
imshow(imbinarize(A,'adaptive'))
It gives the image above, if i delete the rgb2gray it gives a dimesion error.
Well, where did the image I used come from? That seems to be the better one to use.
This is my first time using this community tab so the picture you downloaded was actually a screen shot because i did not think to just attach the image instead i took a screen shot and pasted it here.
Well, like I said, converting to JPEG is a bad thing to do. But if you must convert to JPEG it doesn't seem too hard to threshold the image empirically:
A=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/825090/LIDC-IDRI-0072-1.dcm.jpg');
A = rgb2gray(A);
imshow(A>0.005,[])
Thank you so much for your time, i will try to improve this i believe i can remove the chest from this image thank you again, have a great day.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 6 Dec 2021

Commented:

on 6 Dec 2021

Community Treasure Hunt

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

Start Hunting!