how to find color corrologram of an image?

5 次查看(过去 30 天)
mano
mano 2012-1-19
回答: Gautam 2024-10-23,11:12
how to find color corrologram of an image?

回答(1 个)

Gautam
Gautam 2024-10-23,11:12
Hello @mano,
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;

类别

Help CenterFile Exchange 中查找有关 Modify Image Colors 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by