how to find color corrologram of an image?

조회 수: 3 (최근 30일)
mano
mano 2012년 1월 19일
답변: Gautam 2024년 10월 23일
how to find color corrologram of an image?

답변 (1개)

Gautam
Gautam 2024년 10월 23일
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