How do I generate a colorbar for NDVI?

3 views (last 30 days)
Sri Charan Kakarla
Sri Charan Kakarla on 23 May 2018
Answered: DGM on 23 Mar 2023
Hello, I have the attached image which is an NDVI plot for a field. The software that generates this image does not provide us with a colorbar. Is there a way to create a colorbar for the colors present ONLY in this image and set a range of 0 to 1?
Thank you.
  1 Comment
Vijay Sagar
Vijay Sagar on 23 Mar 2023
You can use colorbar and caxis.
colorbar;caxis([0 1])

Sign in to comment.

Answers (1)

DGM
DGM on 23 Mar 2023
I could be lazy and just assume that it's spring().
That said, if we can assume for a moment that the mapping is linear:
  1. A full-range pseudocolor image in lossless RGB or indexed color
  2. The colormap used to generate the image
  3. The underlying data
Given any two, you can calculate the remaining one. If the image is in a lossy format or if the colormap needs to be extracted from an image of a colorbar, the accuracy will only get worse.
You have only one of the three -- a lossy JPG, so the answer is no.
What information is missing? Well, a lot of information is missing. We don't know whether anything is linear. We don't know the data or whether it spans the full range of the colormap.
We don't know what the start and end colors are, but let's pretend that we did. Consider the following image.
This image has 25 unique values. Let's say we know the end colors are [0.0044 0.2834 0.2834; 0.7345 0.8810 0.5547], and that they correspond exactly to the extrema of this specific image. It should be easy enough to put those colors in between in a nice neat sequence from one color to another,
but the question remains: did that handful of colors come from this map
or this one?
Unless you knew what the data was, you would have no way to know that it came from neither. To assume that it came from the latter merely by appearance would be presuming that both the mapping and the data itself are linear, which isn't the case.
To put the absurdity of dealing with a JPG in perspective,
... your goal would be to take this broad cloud of color points and draw a single line which connects all the points, while progressing smoothly and monotonically from one starting color to another ending color. That's obviously not possible. Could you draw a line which roughly fits the general path? No. There is no general path, only a vague cloud. If accuracy has any merit, you wouldn't try to divine anything from that.
See also:

Tags

Community Treasure Hunt

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

Start Hunting!