<jupyter_start><jupyter_text>Objective:  This problem will study segmentation of color images based on distance in a color space  Loading Required Libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg<jupyter_output><empty_output><jupyter_text>Reading and Displaying Image<jupyter_code>fig = plt.figure(figsize=(8, 8))
I_rgb = ((mpimg.imread('strawberries-RGB.tif')).astype(np.uint8))
img=plt.imshow(I_rgb)
plt.axis('off')
plt.title('Original Image')
plt.show()
I_cube = I_rgb/255
W = 0.2549
a1, a2, a3 = 0.6863, 0.1608, 0.1922<jupyter_output><empty_output><jupyter_text>Distance-Based Color Slicing Equation 7-43 Gonzalez and Wood Book<jupyter_code>I_cube[(np.absolute(I_cube[:,:,0]- a1) > W/2)] = 0.5
I_cube[(np.absolute(I_cube[:,:,1]- a2) > W/2)] = 0.5
I_cube[(np.absolute(I_cube[:,:,2]- a3) > W/2)] = 0.5
I_sph = I_rgb/255
R = 0.1765<jupyter_output><empty_output><jupyter_text>Distance-Based Color Slicing Equation 7-44 Gonzalez and Wood Book<jupyter_code>I_sph[((I_sph[:,:,0] - a1)**2 + (I_sph[:,:,1] - a2)\
       **2 + (I_sph[:,:,2] - a3)**2) > R ** 2] = 0.5
fig = plt.figure(figsize=(14, 6))
plt.subplot(1, 2, 1)
plt.imshow(I_cube)
plt.title('Cubic Transformation', fontsize = 16)
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(I_sph)
plt.title('Spherical Transformation', fontsize = 16)
plt.axis('off')
fig.suptitle('Color-Slicing Transformation for Red Color', fontsize = 20)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17297297297297298, 'fraction_numerical': 0.057432432432432436, 'mean_word_length': 6.154589371980676, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '249121', 'license': 'CC0-1.0', 'n_tokens_mistral': 693, 'n_tokens_neox': 632, 'n_words': 121, 'path': 'Color Image Segmentation/Color Image Segmentation.ipynb', 'repo_name': 'Sinaconstantine/Digital-Image-Processing-EE596-', 'size': '1480'}