Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Mahotas – RGB to LAB Conversion

  • Last Updated : 08 Jul, 2021

In this article we will see how we can covert rgb image to CIE L*a*b* in mahotas. An RGB image, sometimes referred to as a truecolor image, is stored in MATLAB as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. The CIELAB color space (also known as CIE L*a*b* or sometimes abbreviated as simply “Lab” color space) is a color space defined by the International Commission on Illumination (CIE) in 1976.

In this tutorial we will use “lena” image, below is the command to load it.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

mahotas.demos.load('lena')

Below is the lena image 



In order to do this we will use mahotas.colors.rgb2sepiamethod  

Syntax : mahotas.colors.rgb2lab(img)
Argument :It takes image object as argument
Return : It returns image object 
 

Below is the implementation  

Python3




# importing required libraries
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
  
# loading image
img = mahotas.demos.load('lena')
 
  
# showing image
print("Image")
imshow(img)
show()
 
# rgb to lab
new_img = mahotas.colors.rgb2lab(img)
 
# showing new image
print("New Image")
imshow(new_img)
show()

Strong : 

Image

New Image

Another example  

Python3




# importing required libraries
import mahotas
import numpy as np
import matplotlib.pyplot as plt
import os
  
# loading image
img = mahotas.imread('dog_image.png')
       
# filtering image
img = img[:, :, :3]
 
# showing image
print("Image")
imshow(img)
show()
 
# rgb to lab
new_img = mahotas.colors.rgb2lab(img)
 
# showing new image
print("New Image")
imshow(new_img)
show()

Strong : 

Image
 

New Image

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!