how to find color corrologram of an image?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
how to find color corrologram of an image?
0 commentaires
Réponses (1)
Gautam
le 23 Oct 2024 à 11:12
The general approach for computing a corrologram of an image involves colour quantizing the image and computing the spatial correlation with other colors at specified distances.
Below in an example that uses K-means clustering for colour quantization and heatmap to visualize the corrologram
img = imread('peppers.png');
img = im2double(img);
% Quantize the image colors using k-means clustering
numColors = 16; % Number of colors to quantize to
imgReshaped = reshape(img, [], 3);
[~, C] = kmeans(imgReshaped, numColors, 'MaxIter', 200);
% Assign each pixel to the nearest cluster center
[~, idx] = min(pdist2(imgReshaped, C), [], 2);
idx = reshape(idx, size(img, 1), size(img, 2));
% Define the distances for the correlogram
distances = [1, 3, 5];
% Compute the correlogram
correlogram = zeros(numColors, numColors, length(distances));
for d = 1:length(distances)
distance = distances(d);
for i = 1:numColors
% Create a binary mask for the current color
mask = (idx == i);
% Compute spatial correlation with other colors
for j = 1:numColors
% Shift the mask by the specified distance
shiftedMask = circshift(mask, [distance, 0]) | circshift(mask, [0, distance]);
% Compute the correlation
correlogram(i, j, d) = sum(sum((idx == j) & shiftedMask)) / sum(mask(:));
end
end
end
% Display the correlogram
heatmap(rgb2gray(correlogram));
colormap("jet")
colorbar;
0 commentaires
Voir également
Catégories
En savoir plus sur Modify Image Colors dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!