MATLAB Answers

How can I index color bar values from an image generated using Matlab imagesc? I want to be able to index them in the command window.

45 views (last 30 days)
Martins Ezuma
Martins Ezuma on 23 May 2018
Commented: Image Analyst on 24 May 2018
I created a range plot using the matlab command
where G is range data
xlabel('No. of Sweeps')
title('Range Profiles')
clim = get(gca,'CLim');
set(gca, 'CLim', clim(2)+[-40,0]);
axis xy
The image created in colomarp has associated color bar values for each pixel in the image. I want to be able to index row element/pixels using the matlab command and use their associated colobar value instead of the actual pixel value.


Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 May 2018
mat2gray() to do the equivalent of imagesc's mapping between minimum and maximum value. im2uint8() to transform to uint8. Then use ind2rgb.
Or use histc() or histcounts() to transform values to bin numbers, and use the bin numbers to index the colormap. Or just map.
cmap = jet;
mapped_data = 20*log10(abs(G));
min_mapped = min(mapped_data(:));
max_mapped = max(mapped_data(:));
ind = ceil((mapped_data - min_mapped) .* (max_mapped - min_mapped) * size(cmap,1));
ind(ind == 0) = 1;
RGB = cmap(ind, :);


Show 1 older comment
Martins Ezuma
Martins Ezuma on 23 May 2018
Hello Walter, I got the error using your code
Index in position 1 exceeds array bounds (must not exceed 64).
Error in Untitled (line 21) RGB = cmap(ind , :);
Martins Ezuma
Martins Ezuma on 23 May 2018
Thanks Walter. I think I have solved the problem of indexing the pixel intensity generated by matlab imagesec (or any colormap image). Basically, I labeled the image with a variable and use the CData to generate the intensity matrix containing the intensity or colorbar values of all the pixels in the image. I could then index the image pixel by indexing the intensity matrix :
C= a.CData
so I extract the intensity of any pixel (i,j) in my colormap image by the command:
But how do I know which pixel i am indexing by just looking at the image? I use the data cursor on the image tools to select the pixel of interest or type impixelinfo on the command prompt after selecting the pixel. So I basically, click on any pixel, confirm its (x,y) position and intensity value (or colorbar), then, I can confirm the colorbar or intensity value on that pixel by typing C(J,i) instead of C(i,j) on the command prompt....that way, I was able to extract and confirm the pixel value from my imagesc by writing a simple matlab code on my command prompt.
I could even write a for loop using the intensity matrix C to search through the image . That is my goal. To loop through some of the pixels in my colormap image and implement a radar target detection algorithm on each range bin (pixel location).
Image Analyst
Image Analyst on 24 May 2018
Not exactly sure what "how do I know which pixel i am indexing by just looking at the image?" means, but you can see the pixel value at a particular (x,y) location in an image by using ginput(1), impixelinfo(), or imtool(). With the intensity or index, and caxis() and the colormap() you can also get the RGB color the index/intensity is mapped to.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!