“Python-OpenCV” How to Convert Monochrome Image to Pseudo Color Image

Python
higashi
higashi

Hi, I’m higashi.

 

This time, I introduce how to convert monochrome image to pseudo color image as shown below by using Python & OpenCV.

★Original Monochrome Image

Original Monochrome Image

★Pseudo Color Image

Pseudo Color Image from Original Image

By changing to color image, we will be easier to recognize subtle brightness change.

 

This method is often adopted to experimental image.

 

So, let’s get started!!

 

Sponsored Links

How to Convert Pseudo Color Image

At first, I introduce how to convert the pseudo image by using Python-openCV.

The method is below.

color_image= cv2.applyColorMap(base_image, format_of_pseudo_color)

“pseudo_image” and “base_image” is array of image.

“format_of_pseudo_color” can apply below options.

 

★”format_of_pseudo_color” Options

cv2.COLORMAP_JET

cv2.COLORMAP_HOT

cv2.COLORMAP_HSV

cv2.COLORMAP_RAINBOW

 

In addition to the above, you can apply other options.

If you interested in the options, please search by your self.

But I think other than above options is rarely used.

 

Sponsored Links

Sample Program of Making Pseudo Color Image

So, let’s demonstrate how to use above method.

 

The sample program is below.

#import library
import cv2

#load base image
pic=cv2.imread('original.jpg', cv2.IMREAD_GRAYSCALE)
#making COLORMAP_JET
pseudo_color = cv2.applyColorMap(pic, cv2.COLORMAP_JET)
cv2.imwrite('pseudo_color_jet.jpg',np.array(pseudo_color))
#making COLORMAP_HOT
pseudo_color = cv2.applyColorMap(pic, cv2.COLORMAP_HOT)
cv2.imwrite('pseudo_color_hot.jpg',np.array(pseudo_color))
#making COLORMAP_HSV
pseudo_color = cv2.applyColorMap(pic, cv2.COLORMAP_HSV)
cv2.imwrite('pseudo_color_hsv.jpg',np.array(pseudo_color))
#making COLORMAP_RAINBOW
pseudo_color = cv2.applyColorMap(pic, cv2.COLORMAP_RAINBOW)
cv2.imwrite('pseudo_color_rainbow.jpg',np.array(pseudo_color))

It just use above method after loading base image and save converted image.

 

Sponsored Links

Result of Sample Program

The result of this program is below.

summary of program conducted result

The two on the left are above program and original monochrome image.

And four on the right are pseudo color image converted from original image.

 

Since the above image is too small, I show all images respectively at below.

◆Original Image

Original Monochrome Image

◆COLORMAP_JET

Pseudo Color Image from Original Image (JET)

◆COLORMAP_HOT

Pseudo Color Image from Original Image (HOT)

◆COLORMAP_HSV

Pseudo Color Image from Original Image (HSV)

◆COLORMAP_RAINBOW

Pseudo Color Image from Original Image (RAINBOW)

 

higashi
higashi

I think JET or HOT is Good!!

 

That’s all. Thank you!!

コメント