Over 10 Million Study Resources Now at Your Fingertips

Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Pages: 5
Words: 1009

Cluster Spatial Pixels CIELab Homework Answers Needed

Your Question:

macbeth = cv2.imread("Images/macbeth_cc.jpg")

macbeth_original_cieLab = cv2.cvtColor(macbeth,cv2.COLOR_BGR2LAB)

# macbeth_resized = cv2.resize(macbeth,(desired_width,desired_height),interpolation=cv2.INTER_AREA)

# macbeth_cieLab = cv2.cvtColor(macbeth_resized,cv2.COLOR_BGR2LAB)

desired_width = int(desired_height * aspect_ratio)

macbeth_resized = cv2.resize(macbeth_original_cieLab,(desired_width,desired_height),interpolation=cv2.INTER_AREA)

#this function converts from opencv to normal CIELAb values

# def convertToLab(array):

# a = float(array[col][row][1])

# b = float(array[col][row][2])

# b = b - 128.0

# array[col][row][1] = a


#this step involves normalizing data

a_channel_normalized = (a_channel - np.min(a_channel)) / (np.max(a_channel) - np.min(a_channel))

b_channel_normalized = (b_channel - np.min(b_channel)) / (np.max(b_channel) - np.min(b_channel))

optimal_k = -1

myExit = 0 # keep track to exit from loop

silhoutte_avg = silhouette_score(normalized_cielab_array,labels)

print(f"silhouete average: {silhoutte_avg}")


myExit += 1

macbeth_original_cieLab_reshaped2D = macbeth_original_cieLab_reshaped.reshape((-1,3))

macbeth_kmeans = KMeans(n_clusters=optimal_k,random_state=0).fit(macbeth_original_cieLab_reshaped2D)

The next step of the project should be to run your clustering algorithm in each of the masks, find spatial clusters and classify each pixel according to its [row, column] position in the image.

Step By Step Answers with Explanation

To achieve the goal of separating spatial clusters of pixels within each of the masks generated by your KMeans clustering algorithm, you'll need to follow a step-by-step process. I'll outline the procedure for you:

num_labels, labels = cv2.connectedComponents(cluster_mask.astype(np.uint8))

The labels array will contain integers where each unique value represents a different spatial cluster within the mask.

  • Here, spatial_clusters is a dictionary where keys are cluster labels, and values are arrays of [row, column] positions of pixels within that spatial cluster.

  • Optional: Visualize Spatial Clusters: If you want to visualize the spatial clusters, you can mark them on your original image using different colors or contours. This step is optional but can be helpful for debugging and analysis.

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Make payment
Document download
Download File
PageId: ELIB443779
Uploaded by :
Page 1 Preview
for example the top left corner and the top right
Sell Your Old Documents & Earn Wallet Balance