Clear Filters
Clear Filters

Mapping colored image on grayscale

2 views (last 30 days)
Sehrish on 23 Jul 2012
Commented: Image Analyst on 13 May 2020
I have a gray scale image of brain and a colored tumor image. i want to map the tumor colored image on the gray scale image, can i do this???
the brain image is, while colored image is
i have used for loop for mapping but the result is, but this is not correct i guess, how can this be corrected
abisha abisha
abisha abisha on 13 May 2020
Edited: Image Analyst on 13 May 2020
Did you have any code related to pancreas cancer detection or diagnosis?
Image Analyst
Image Analyst on 13 May 2020
No, I've never done that.

Sign in to comment.

Answers (4)

Ryan on 23 Jul 2012
Edited: Ryan on 23 Jul 2012
I = imread('Brain.jpg');
Tumor = imread('Tumor.jpg');
ThresholdValue = 10; % You'll want to find the best value
mask = Tumor <= ThresholdValue;
figure,imshow(I),hold on
h = imshow(Tumor);
Output image:
Sehrish on 24 Jul 2012
thanks a lot it really works for all images
Ryan on 25 Jul 2012
Edited: Ryan on 25 Jul 2012
Glad to help. I was playing around with it and 15 seems to be the best threshold value.
You could also use:
mask = Tumor >= ThresholdValue;

Sign in to comment.

Image Analyst
Image Analyst on 23 Jul 2012
Edited: Image Analyst on 23 Jul 2012
Segment the image, say, by thresholding the intensity to get a binary image of where the tumor is. Then multiply it by the original image to get an image of only the tumor. Then apply a colormap with the colormap() function. Something like (untested)
binaryImage = grayImage > thresholdValue; % You decide what thresholdValue is
maskedImage = uint8(binaryImage) .* grayImage;
imshow(maskedImage, []);
With this case, binary image can be more general and sophisticated than the simple thresholding I showed here.
Or, you can simply do it with a colormap, like this:
thresholdValue = 130; % gray level where the colors start.
numberOfColorValues = 256 - thresholdValue + 1;
myColorMap = gray(256);
myColorMap(thresholdValue:end, :) = flipud(autumn(numberOfColorValues));

Matt Kindig
Matt Kindig on 23 Jul 2012
What do you want the resulting image to look like? Do you want the brain to render as gray, with the tumor shown in the flame-like colors? If so, you can follow this general approach:
1. Convert the brain image to RGB, using ind2rgb() with the original (gray) colormap.
2. Convert the tumor image to RGB, using ind2rgb() with the color (hot?) colormap.
3. Use logical indexing to identify all parts of the tumor image that are black (zeros).
4. Replace the brain image with the tumor image for those given pixels.
Sehrish on 23 Jul 2012
yeah i want to replace the zero pixels of tumor image with brain image
Image Analyst
Image Analyst on 23 Jul 2012
The second chunk of code in my answer will do that. But you need to say if the tumor can be simply be determined by intensity alone, or did you do something more to find it, like get rid of small regions, do hole filling, etc. If you didn't do anything fancy like that and it's simply based on intensity then my code will display it like you wanted. If you want to convert the colormapped image into a RGB image, then you can use ind2rgb(grayImage, myColorMap) to get the RGB image.

Sign in to comment.

Walter Roberson
Walter Roberson on 23 Jul 2012
You need scaling and alignment information, which it is not clear that you have. Is the assumption that the tumor and brain image are already scaled to the same size and are positioned at the same place in their images?
Once they are scaled and aligned, image() or imagesc() the two images into place. On the top image (the one with the tumor), set the AlphaData to 0 for each pixel where the grayscale image is to show through.

Community Treasure Hunt

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

Start Hunting!