how to find color corrologram of an image?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
how to find color corrologram of an image?
0 comentarios
Respuestas (1)
Gautam
el 23 de Oct. de 2024 a las 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 comentarios
Ver también
Categorías
Más información sobre Modify Image Colors en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!