# adding bar legend of an morphological image (Atomic force microscopy image)

I want to analysis a topography of the following image. I want to add a bar legend in this image associated with the appropriate colour of the image. Following is the image:

For your reference Here I have attached a similar image which I got from another software. How can I do this using Mathematica (I am using Mathematica 10)? Any suggestion will be really helpful. In my image white colour represent the particle with height 17nm and dark red represent background with height -2nm. i.e in bar legend white colour is 17nm and dark colour is -2nm.

• An essential piece of the puzzle is missing in accomplishing what you desire: you must necessarily know what the colors are to be interpreted as (i.e., what does white signify? What does black or red indicate?) and be able to give this information to the Mathematica software. Once this is accomplished, construction of bar legends is a trivial task in comparison. Commented Jun 18, 2021 at 3:29
• white colour represent 17nm and dark red represent -2 nm height. and I want to construct a bar legend within this range. Commented Jun 18, 2021 at 9:17

More of an extended comment, but perhaps have a look at this resource function?
(All credit goes to Mark Greenberg)

Using it quickly, I was able to get something like this:

img = Import["https://i.sstatic.net/NPQX8.jpg"];
cf = ResourceFunction["ImageColorFunction"][img, SampleOrder -> "Red"];
bar = BarLegend[{cf, {0, 1}}, LegendMarkerSize -> {25, 150}];
ImageCompose[img, bar // Rasterize, {Right, Top}, {Right, Top}]


PS: You mentioned you're using Mathematica 10, which I assume does not know of ResourceFunction. The source notebook from the resource function above seems to be using fairly standard functions, so perhaps you're in luck. In any case, the source-code should be useful to peruse.

• +1 for addressing the image analysis and referencing the resource function link. Commented Jun 17, 2021 at 13:39

Without the data you want to plot (or an approximation of the data) it becomes a little difficult to offer a full solution.

That said, the following (really offered as an extended comment), may provide you with some strategies to approach what you want to do.

It seems like you want to look at these sorts of: images:

and use a BarLegend.

You can find many examples in the documentation, e.g., see ComplexPlot

ComplexPlot[(z^2 + 1)/(z^2 - 1), {z, -2 - 2 I, 2 + 2 I}, PlotLegends -> Automatic]

Or ReliefPlot

ReliefPlot[ Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}], ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

Essentially, if you select an appropriate type of Plot (ComplexPlot, ReliefPlot), to present the data, you'll have a ready option of using BarLegend.

You can additionally create a BarLegend and use Show to display it with an image.

Again, without a bit more information responders will likely need to guess what you want to do.

Maybe you just want to analyze the graphic image itself rather than generate it from the data of an Atomic force microscope (AFM) image.

If so, take a look in the documentation at: Image Processing & Analysis.

ImageMeasurements might then prove useful.

ImageMeasurements[image, "MeanIntensity"]

{0.194848, 1.}

ImageMeasurements[image, "Entropy"] // N

7.00746

Information[image]