3

I would like to color code the brightness values of an image (8bit, gray scale, 1600*1200 pixels). Each pixel should be color coded according to its brightness value using a dedicated color table.

An example image can be downloaded here.

The brightness histogram is:

Histogram[Flatten@ImageData@image, {1/256}, ScalingFunctions -> "Log",
  Frame -> True, FrameLabel -> {{"# of Pixels", ""}, {"Brightness", ""}}, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 40, 
  FontFamily -> "Calibri"}, PlotRange -> {{0, 1}, All}, 
  ImageSize -> 2000, ImagePadding -> {{All, All}, {All, 50}}]

So most of the brightness values are around 0.045.

enter image description here

I tested ListContourPlot but it is extremely slow (AbsoluteTiming gives 91 sec).

colTable = {{Black}, 
   Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 0.2, 1, 0.1}]}; 
colTable = Flatten[colTable]

ListContourPlot[ImageData@image, PlotLegends -> Automatic, 
 ColorFunction -> (Blend[colTable, #] &), Contours -> 10]

How can I improve the contrast of the color coded image?

Do you know an other or faster solution?

enter image description here

mrz
  • 11,686
  • 2
  • 25
  • 81

2 Answers2

1

Update

New and fast (4 seconds) way to achieve plot and scale.

colTable = {{Black}, Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 0.2, 1, 0.1}]};
colTable = Flatten[colTable];

ArrayPlot[ImageData[imageOrg], ColorFunction -> (Blend[colTable, #] &),
          PlotLegends -> Automatic, FrameTicks -> All]

enter image description here


Other methods:

Colorize

Colorize[imageOrg, ColorFunction -> (Blend[colTable, #] &),
         ColorFunctionScaling -> False] //Timing

2.15281

enter image description here

How do I apply a ColorDataFunction[] to a grayscale image?


Image@Raster[ImageData[imageOrg, DataReversed -> True],
             ColorFunction -> (Blend[colTable, #] &)] // Timing

2.19961

enter image description here

Young
  • 7,495
  • 1
  • 20
  • 45
0

Another color table:

colTable = 
 Flatten@{Table[Black, {x, 0, 12, 1}], 
   Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 1/10, 1, 1/10}], 
   Table[Black, {x, 24, 256, 1}]}

ArrayPlot[ImageData[image], ColorFunction -> (Blend[colTable, #] &), 
 PlotLegends -> Automatic, FrameTicks -> All]

enter image description here

Colorize[image, ColorFunction -> (Blend[colTable, #] &)]

enter image description here

mrz
  • 11,686
  • 2
  • 25
  • 81