mashadab / python-colormap-image-digitizer

This short python script digitizes image made with any Python colormaps and converts it to another colormap while extracting out values.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python-colormap-image-digitizer

This short python script reads/digitizes an image (JPG/PNG) made with a specific colormap in Python and converts it to another colormap as well as extracts out values.

Getting Started

Steps

  1. Crop the initial image (Figure 1) using other software

Figure 1: Initial uncropped JPG image made in viridis colormap.

  1. Read the cropped image (Figure 2)

Figure 2: Cropped image made in viridis colormap.

  1. In the code, mention the input colormap (needs to be in Python).

  2. Make the map between the input and output colormap.

  3. Finally, the input image RGB values can be multiplied with the coefficients to get the output image (Figure 3).

Figure 3: Output temperature contour plot with Reds colormap.

Dependences

hyperbolic-infiltration-theory requires the following packages to function:

Quick Usage

Run the image-digitizer.py Python script.

What is happening in the code

We make a one-to-one map in between input colormap (RGB) and the Greys (g) colormap. For that we first define the two maps. Then solve for the coefficients a,b,c:

g = a*R + b*G + c*B

For the complete, discretized colormap we can write

b = A * X with b = [g_1;g_2;g_3,...], A = [R_1,G_1,B_1; R_2,G_2,B_2; ...] and X = [a;b;c]

So, X = (A^T A)^{-1} A^T b

Once we find the color vector X, we multiply the RGB array in each pixel with it.

About

This short python script digitizes image made with any Python colormaps and converts it to another colormap while extracting out values.

License:MIT License


Languages

Language:Python 100.0%