Applying a mask to a image

Hi,
I have 60 CT slices and by applying certain processing steps, now I created maps (maybe we can call this as a mask also) for each one of the slices. What I want to do now is to put my particular mapping on to the original CT slice and see the matching. But the problem is that: I cannot check it by directly looking at the pixel values. Because my mapping's pixel values are between 0 and 114 whereas original CT image's are uint16. Also, adjusting pixel values by multiplying by a certain number cannot be considered as a solution for my problem.
Is there a way like for example: I colorize my mapping as red and when I put my mapping on the original CT image, then matching pixels will be shown as red. Or do you have any other suggestions?
Regards

4 Comments

Should the shade of red be proportional to the mask value? If so then what mask value should indicate complete red? Should a mask value of 0 (only) indicate where the CT image shows through? Or should it be that the mask value should be interpreted as a transparency, 0 being completely transparent? If so what value should indicate full opaque ?
Please state the difference between "mapping" and "mask". A mask is usually a logical array or an integer array with values of 0 or 1. Why are your values going between 0 and 180? I don't understand why you want to colorize slices. How does that solve your problem of applying a mask to the slices?
Amadeus
Amadeus on 18 Dec 2012
Edited: Amadeus on 18 Dec 2012
Walter first of all thank you for your answer. 114 will indicate complete red, if mask value is 0 at a particular pixel, then I want to be able to see the CT image value when I apply the mask. (My mask is supposed to indicate some fibers on the CT data.)
Amadeus
Amadeus on 18 Dec 2012
Edited: Amadeus on 18 Dec 2012
@ImageAnalyst 0-114 (I rechecked now and 180 is wrong) indicates how many fibers go over that voxel. I kept the record of that in order to indicate the voxel with 114 fibers more distinct than a voxel with 8 fibers.
Applying a red color to the mask was just a thought. I tried simply adding my mask to original CT data but output is not very clear. Therefore I am looking for better solutions.

Sign in to comment.

 Accepted Answer

CTRGB = cat(3, YourCTImage, YourCTImage, YourCTImage);
hCT = image(CTRGB);
MaskImage(:,:,3) = zeros(size(YourCTImage)); %also sets G plane to 0
MaskImage(:,:,1) = 1;
maskalpha = double(YourCTMask) ./ 114; %1 for maximum count
hMask = image(MaskImage, 'AlphaData', maskalpha); %not imshow() or imagesc()

6 Comments

Amadeus
Amadeus on 18 Dec 2012
Edited: Amadeus on 18 Dec 2012
CTRGB = cat(3, nii.img, nii.img, nii.img);
hCT = image(CTRGB);
MaskImage(:,:,3) = zeros(size([96 96 60])); %also sets G plane to 0
MaskImage(:,:,1) = 1;
maskalpha = double(N) ./ 114; %1 for maximum count
hMask = image(MaskImage, 'AlphaData', maskalpha); %not imshow() or imagesc()
Error using image
Error using image
Indexed CData must be size [MxN], TrueColor CData must be size [MxNx3]
for slicenum = 1 : size(nii.img,3)
cla
CTRGB = nii.img(:,:,[slicenum slicenum slicenum]);
hCT = image(CTRGB);
MaskImage = zeros(size(CTRGB));
MaskImage(:,:,1) = 1;
maskalpha = double(N) ./ 114; %1 for maximum count
hMask = image(MaskImage, 'AlphaData', maskalpha); %not imshow() or imagesc()
title(sprintf('Slice #%d', slicenum));
pause(0.5);
end
Using "N" as your per-pixel fibre count is not at all self-explanatory; I would recommend using a better variable name.
Amadeus
Amadeus on 18 Dec 2012
Edited: Amadeus on 18 Dec 2012
I still get the following error:
Error using image
Bad property value found.
Object Name : image
Property Name : 'AlphaData'.
Is this problem related to N variable? It is 96*96*60 uint16. By the way,you are right N is a bad variable name. I was going to fix it anyway.
edit: Allright, I solved the problem by just using maskalpha = double(N(:,:,slicenum)). I guess I need to take a rest = )
Walter Roberson
Walter Roberson on 18 Dec 2012
Edited: Walter Roberson on 18 Dec 2012
? I already had double(N)
You should not be using N directly: you need to divide it by the 114 to get the correct alpha values. And you should not do the division until after the double()
Amadeus
Amadeus on 18 Dec 2012
Edited: Amadeus on 18 Dec 2012
./114 is still there. Here is the whole line:
maskalpha = double(N(:,:,slicenum)) ./ 114; %1 for maximum count
By the way I felt like I am only viewing the slices from the Mask. Exactly which part of the code uses the original CT image slices? hCT seems to be not used.
The line
CTRGB = nii.img(:,:,[slicenum slicenum slicenum]);
is selecting the current slice from the original image. The image() of it is displaying that slice. The assignment to hCT of the image() is giving you the handle of the image object created. In the code shown, that handle is not used because I used cla() to delete all the current axis contents instead of using delete(hCT) and delete(hMask) to delete the two images selectively.
You might possibly want to increase the pause() to 1 or more; that is how long each slice will be displayed. Since you didn't say what you wanted to do with all the various slices, I just display each of them momentarily and go on to the next.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!