Set specific pixels to BLACK after Imagesc() and Colormap(jet())
3 views (last 30 days)
Show older comments
I'm writing an application that displays an array of experimental data (~50x50) using imagesc(). I'm using the jet colormap.
Front panel activity calls a threshold function that should turn specific pixels to black. I can access the correct pixels from my threshold call, but when I set the CData value to 0, it displays the jet colormap value (blue or red).
arrayname = get(this.img, 'CData');
arrayname(numy,numx,:)==??????;
set(this.img,'CData',arrayname);
Is there an easy way to set that pixel to black without checking the colormap? I think making that pixel transparent will also work.
I think I cannot simply rewrite the colormap with 0 index pointing to black, as some of my data ranges [-90,90].
0 Comments
Answers (1)
Image Analyst
on 27 Sep 2013
Try this and tell me if it solves your issue:
% Create sample data in the range -90 to +90
dblImage = 180*rand(50,50)-90;
% Set some rows to black
dblImage(20:25, :) = 0;
% Define a custom colormap - use jet.
myColorMap = jet(256);
% Find out what row a value of 0 would be in.
minValue = min(dblImage(:))
maxValue = max(dblImage(:))
zeroIndex = ceil((0-minValue) / (maxValue - minValue) * 256)
% Make that row of the colormap be zero.
myColorMap(zeroIndex, :) = [0,0,0]
% Display it
imshow(dblImage, [], 'InitialMagnification', 1000);
% Apply our custom colormap.
colormap(myColorMap);
colorbar;
If you don't have the Image Processing Toolbox, you can use image() instead of imshow().
2 Comments
Image Analyst
on 28 Sep 2013
There are some more complicated ways. For example you could create some color map (with no black) and then apply it with ind2rgb() so that the image is now an RGB image. Then you could just go through and set the pixels in the rgb image that you want to be black to [0,0,0]. Of course since it's now an rgb image, the color map no longer is used. But that way, no other pixels at all will be black - just the ones you want to be black will be black.
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!