MATLAB: I have mha file, how to do image segmentation of this data

.mhaImage Processing Toolboximage segmentationMATLAB

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

Best Answer

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.