You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
I have mha file, how to do image segmentation of this data
6 views (last 30 days)
Show older comments
This is in continuation to a previous que which I already asked regarding readdata3d. dont know how to proceed further.....
Sir here is the data attached of brain mri scan. It's in mha format and is a 3d Image. We have to convert this 3d into a 2d image and use watershed algorithm to detect the tumor in the brain. The mha format is not being supported. Hence I am not able to upload it. If any email id is given I would send it.
I've used the following code:
[V,info]=ReadData3D
for slice = 1 : numberOfSlices
thisSlice = V(:,:, slice);
baseFileName = sprintf('Slice %d.png', slice);
fullFileName = fullfile('F:\final yr project', baseFileName);
imwrite(thisSlice, fullFileName);
end
The final image should be like the one I attached above.
The image should be gray scale analysed. So how to use these mha files to covert the 3d to above mentioned like pic. For further analysis using watershed
Can you please suggest me how this can be done and also can you please help me with the code if possible
31 Comments
Rik
on 14 Jan 2018
rohith bharadwaj
on 14 Jan 2018
I have a .mha file. I have to do watershed segmentation on the data to find a tumour. I don't know how to start. I am not able to handle .mha files. Ive tried ReadData3D but I'm getting an error, not able to resolve. how to import .mha files to matlab, plot them, covert the 3D image into many 2D images by slicing the 3D image into different layers
Jan
on 14 Jan 2018
Are you talking about https://www.mathworks.com/matlabcentral/fileexchange/29344-read-medical-data-3d? Please post much more details.
rohith bharadwaj
on 14 Jan 2018
Edited: Walter Roberson
on 15 Jan 2018
ive typed ReadData3D in command window and loaded the .mha file.
I'm getting as:
RescaleSlope not available, assuming 1
RescaleIntercept not available, assuming 0.
also tried
[V,info]=ReadData3D('abc.mha');
but getting as : could not open file abc.mha
Is there any other method for analysis of .mha files
rohith bharadwaj
on 14 Jan 2018
I tried [V,info]=ReadData3D I got data in V and info
V is of order 240x240x155
and info is of 1x1
Now how to proceed further. how to plot V, convert this data into different layers(2D IMAGE by slicing)
Jan
on 14 Jan 2018
@rohith: Please be so kind and explain, which function you are using. "readdata3d" is not a built-in function. If you use a 3rd party tool, the readers have to know this.
The message "could not open file abc.mha" might mean, that there is no file with this name in the current folder. Perhaps you have to specify the complete path?
If you get your V as [240 x 240 x 155] array, you get the k.th slice by V(:, :, k).
rohith bharadwaj
on 14 Jan 2018
I don't know much about the function. but this line of code is not working every time. Is there any similar function in matlab to get similar output. readdata3d enables us to use .mha files. Is there another method to handle these extension files in matlab
Image Analyst
on 14 Jan 2018
ReadData3D is not a built-in function. Contact whomever gave you the .mha files and ask them if they have a reader for their files that works.
Jan
on 14 Jan 2018
@rohith: While you do not know much about the function, I do not know anything about it. I asked twice already for an explanation where you got this function from. Unfortunately you do not reveal this important detail. How could we know, if there is another tool, if you do not tell us, which tool you are using? How could we know a tool to get a similar output, without knowing to what it should be similar?
In addition your comments sound like you were able to import the file successfully already. So why are you looking for a different tool? I think your current problem is the plotting. Then please explain the details of what you want to plot how.
Image Analyst
on 14 Jan 2018
Here are 51 posts about mha files: https://www.mathworks.com/support/search_results.html?q=mha&submitsearch= I'm sure you can find something that works within those posts.
If a given mha reader only works for some files, then perhaps your reader and files don't match up as far as "flavors" of mha files that they work with. Try a different reader or make sure that your mha file is created with all the information that your reader expects to find.
rohith bharadwaj
on 15 Jan 2018
sir can you share your email id so that I can share my codes and explain my work in detail
thank you
Walter Roberson
on 15 Jan 2018
RescaleSlope not available, assuming 1
RescaleIntercept not available, assuming 0.
Those are not errors. Dicom images have properties by those names that are used to make it practical to store floating point values as linear integer values instead, and the messages are just telling you that the data file you were reading does not make those properties available and will be interpreted "as-is". These properties mostly make a difference for CT images; you probably do not care about them.
Walter Roberson
on 15 Jan 2018
It is not up to me to provide the email address for Image Analyst. I know from past discussions that he does not email for these purpose: he would neither send nor receive email on these topics.
rohith bharadwaj should post the link to the ReadData3D that they are using, and if permitted, should attach the mha file (it would be necessary to zip it.)
Rik
on 15 Jan 2018
Sorry for the misunderstanding. I meant that rohith bharadwaj could just post the text of his e-mail here, instead of sending it to only Image Analist. If he is allowed to share it by e-mail, he should be allowed to post it here.
rohith bharadwaj
on 15 Jan 2018
Sir here is the data attached of brain mri scan. It's in mha format and is a 3d Image. We have to convert this 3d into a 2d image and use watershed algorithm to detect the tumor in the brain
rohith bharadwaj
on 15 Jan 2018
Edited: Walter Roberson
on 16 Jan 2018
I've used the following code:
[V,info]=ReadData3D
for slice = 1 : numberOfSlices
thisSlice = V(:,:, slice);
baseFileName = sprintf('Slice %d.png', slice);
fullFileName = fullfile('F:\final yr project', baseFileName);
imwrite(thisSlice, fullFileName);
end
rohith bharadwaj
on 15 Jan 2018
The image should be gray scale analysed. So how to use these mha files to covert the 3d to above mentioned like pic. For further analysis using watershed
rohith bharadwaj
on 15 Jan 2018
Can you please suggest me how this can be done and also can you please provide me with the code if possible
Jan
on 15 Jan 2018
@rohit: I do not see attached data. You still keep it as a secret, which "ReadData3D" function you use and you simply ignore my corresponding questions. This is a strange behavior if you ask for assistance.
It is not clear what you are asking for now. Does the posted code work? It is not possible to post useful code based only on the description: "further analysis using watershed".
Please read and consider the link Rik has suggested 18 comments before: https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer . Your current way of asking does not allow to help you and therefore this wastes your time only. The members of the forum really do like to help you, but give them a chance to do this.
rohith bharadwaj
on 15 Jan 2018
Sir I wanted to post the data. But it is in mha format. Hence the file isn't uploading. Could you give any mail id so that I can send you the data
rohith bharadwaj
on 15 Jan 2018
Edited: rohith bharadwaj
on 16 Jan 2018
I want to use
baseFileName = 'bac.mha';
fullFileName = fullfile('F:', baseFileName)
I am getting these errors
Error using imread (line 350) Unable to determine the file format. Error in brainana (line 34) grayImage = imread(fullFileName);
Im getting black white images when took one image. but i have to do my analysis on grayscale image. the mha data should be converted to 2D similar to image attached above.
Image Analyst
on 16 Jan 2018
Come on rohith, you need to think a little before you do things. Now you know that imread() does not work with .mha files and your ReadData3D() function does work with them - you've already told us that. So why didn't you change from imread() to ReadData3D() in the demo???
rohith bharadwaj
on 16 Jan 2018
Edited: rohith bharadwaj
on 16 Jan 2018
You are not getting my point. ReadData3D is giving 240x240x155 matrix. Ive sliced that to form a 2D image. but the image is in black and white(Slice 80.png attached). I dont want that image. I want greyscale image shown above for analysis. Its not compulsory to use ReadData3D. if there is any other better or easy way of approach Please let me know. I just want to convert that 3d to 2d grayscale images. After that i'll use watershed to detect tumour
Image Analyst
on 16 Jan 2018
How do you want to convert it? Take the mean along the slice direction? Take the maximum intensity projection? Take just one slice? I have no idea.
Accepted Answer
Walter Roberson
on 16 Jan 2018
Your data is not black and white. It is, however, in CT units, with values from 0 to 1509. To make visual sense out of that you need to rescale it. Use this:
V = mat2gray(V);
after you read the data in. That will scale the values in the array so that the maximum value is 1 and the minimum is 0. You can then extract slices and imshow() or image() them.
13 Comments
rohith bharadwaj
on 16 Jan 2018
Yes Thank you I got my 2d grayscale image.
Is there any watershed algorithm to find the tumour.
Walter Roberson
on 16 Jan 2018
"L = watershed(A) returns a label matrix L that identifies the watershed regions of the input matrix A, which can have any dimension"
Dileep Kumar Kothamasu
on 12 Mar 2018
I used the same code as mentioned above and I got 176 slices. so which slice can be used for preprocessing and segmentation. Or should we use whole 176 slices for preprocessing and segmentation if so how to do it.please attach the code if available or comment the solution
Walter Roberson
on 12 Mar 2018
Any slice that has content can be used for preprocessing and segmentation. Some slices will not happen to have the feature you are interested in, but you need to do pre-processing and segmentation in order to figure out what the slice does have.
Dileep Kumar Kothamasu
on 12 Mar 2018
I didn't get you. Can you briefly describe that? Do you mean we have to consider all the slices?
Walter Roberson
on 12 Mar 2018
When you look at any given slice, how do you know whether it contains whatever it is you are looking for?
Dileep Kumar Kothamasu
on 13 Mar 2018
Edited: Dileep Kumar Kothamasu
on 13 Mar 2018
Ya That's what my doubt is to so how can I know which slice can be used? suppose in one image slice no. 80 looks fine and in another image slice no. 96 looks good so should I use slice no's 80 and 96 for preprocessing and segemtation and I am not sure about 80 and 96 slices are good because 80,81,82 slices are good with small variations in brain size so I confused can you help me in this?
Image Analyst
on 13 Mar 2018
Yes, you can use the whole 3-D volumetric image (all slices stacked together). That's what "which can have any dimension" means - 3-D as well as 2-D images are allowed.
Dileep Kumar Kothamasu
on 15 Mar 2018
Thank You, So how can I take whole slices stacked together go for further process
Dileep Kumar Kothamasu
on 17 Mar 2018
Walter code helped me to rescale them only.I don't know which slice I have to get feature extraction technique. Please help me. I got stuck on this problem and didn't move forward!!
Walter Roberson
on 17 Mar 2018
The researchers I worked with generally normalized the brain images, and then after that trained on a bunch of normal brains and a bunch with tumors. They did not use segmentation and preprocessing that I recall. But it has been over 15 years since I did any brain related work, and I was not much involved with the brain analysis theory (I was more responsible for interface and graphics and general program structure for the brain work.)
Image Analyst
on 17 Mar 2018
Because of your ambiguous posts, we don't know if you want to segment the 3-D volume, or if you want to segment out a 2-D region in just one slice. Why don't you start your own question, rather than keep bugging rohith, and post some of your slice images? click here
More Answers (1)
Image Analyst
on 15 Jan 2018
It looks like you got the mha reading part working so now you just need to find the tumor. Assuming it's bright, just threshold and call regionprops. It works in 2-D or 3-D. See attached demo.
See Also
Categories
Find more on 3-D Volumetric Image Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)