Skip to content
Related Articles

Related Articles

Improve Article
Mahotas – XYZ to LAB Conversion
  • Last Updated : 29 May, 2021

In this article we will see how we can covert xyz image to rgb image in mahotas. Xyz is an additive color space based on how the eye interprets stimulus from light. Unlike other additive rgb like Rgb, Xyz is a purely mathematical space and the primary components are “imaginary”, meaning we can’t create the represented color in the physical by shining any sort of lights representing x, y, and z. 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.. We use mahotas.colors.rgb2xyz method for converting rgb image to xyz image.

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

mahotas.demos.load('lena')

Below is the lena image  

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



Syntax : mahotas.colors.xyz2lab(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 iamge
img = mahotas.demos.load('lena')
 
# rgb to xyz
xyz_img = mahotas.colors.rgb2xyz(img)
 
# showing new image
print("Image")
imshow(xyz_img)
show()
 
# getting lab image
new_img = mahotas.colors.xyz2lab(xyz_img)
 
# showing image
print("New Image")
imshow(new_img)
show()

Output : 

Image

New Image

Another example  

Python3




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

Output : 

Image 

New Image

 

 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




My Personal Notes arrow_drop_up
Recommended Articles
Page :