ASSIGNMENT - 1
Name : Syed Taha Ashraf (DS -005/2023)
Name: Syed Hasnain Haider Kazmi (CT -
021/2023)
# Import libraries
from skimage import io
from skimage import color
from pylab import *
# Read image
img = [Link]('/content/[Link]')
# Define a list of conversion functions
conversions = [
(color.rgb2hsv, color.hsv2rgb), (color.rgb2xyz, color.xyz2rgb),
(color.rgb2gray, color.gray2rgb), # Changed rgb2grey to rgb2gray
(color.rgb2yuv, color.yuv2rgb), (color.rgb2lab, color.lab2rgb),
(color.rgb2yiq, color.yiq2rgb), (color.rgb2ypbpr, color.ypbpr2rgb),
]
# Initialize the image for conversion
converted_img = img
# Loop through the conversion functions
for rgb_conversion, inverse_conversion in conversions:
# Convert to the target color space
converted_img = rgb_conversion(converted_img)
figure()
[Link](converted_img)
title(f'Converted to {rgb_conversion.__name__}')
# Show the converted image figure() [Link](converted_img)
# Convert back to RGB
converted_img = inverse_conversion(converted_img)
# Show the final RGB image
figure()
[Link](converted_img)
title('Converted back to RGB')
show()
img_hsv = color.rgb2hsv(img)
figure()
[Link](img_hsv)
title('Converted to HSV')
show()
img_rgb_from_hsv = color.hsv2rgb(img_hsv)
figure()
[Link](img_rgb_from_hsv)
title('Converted back to RGB from HSV')
show()
img_xyz = color.rgb2xyz(img)
figure()
[Link](img_xyz)
title('Converted to XYZ')
show()
img_rgb_from_xyz = color.xyz2rgb(img_xyz)
figure()
[Link](img_rgb_from_xyz)
title('Converted back to RGB from XYZ')
show()
img_grey = color.rgb2gray(img)
figure()
[Link](img_grey, cmap='gray')
title('Converted to Greyscale')
show()
from skimage import color, io
import [Link] as plt
# Convert the grayscale image to RGB
img_rgb_from_grey = color.gray2rgb(img_grey)
# Display the original grayscale image
[Link](figsize=(10, 5))
[Link](1, 2, 1)
[Link](img_grey, cmap='gray')
[Link]('Original Grayscale Image')
[Link]('off') # Hide axes
# Display the converted RGB image
[Link](1, 2, 2)
[Link](img_rgb_from_grey)
[Link]('Converted to RGB')
[Link]('off') # Hide axes
[Link]()
img_yuv = color.rgb2yuv(img)
figure()
[Link](img_yuv)
title('Converted to YUV')
show()
img_rgb_from_yuv = color.yuv2rgb(img_yuv)
figure()
[Link](img_rgb_from_yuv)
title('Converted back to RGB from YUV')
show()
img_lab = color.rgb2lab(img)
figure()
[Link](img_lab)
title('Converted to LAB')
show()
img_rgb_from_lab = color.lab2rgb(img_lab)
figure()
[Link](img_rgb_from_lab)
title('Converted back to RGB from LAB')
show()
img_yiq = color.rgb2yiq(img)
figure()
[Link](img_yiq)
title('Converted to YIQ')
show()
img_rgb_from_yiq = color.yiq2rgb(img_yiq)
figure()
[Link](img_rgb_from_yiq)
title('Converted back to RGB from YIQ')
show()
img_ypbpr = color.rgb2ypbpr(img)
figure()
[Link](img_ypbpr)
title('Converted to YPbPr')
show()
img_rgb_from_ypbpr = color.ypbpr2rgb(img_ypbpr)
figure()
[Link](img_rgb_from_ypbpr)
title('Converted back to RGB from YPbPr')
show()