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.

19 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.

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, :);
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!