Comparing colors against Palette
Afficher commentaires plus anciens
Hi, I read in a low res image and read the colours it uses into a palette.
y=200;
x=200;
img=imresize(imread('image.jpg'), [x y]);
% imshow(img);
[~, Palette] = kmeans(reshape(double(img(:)),M*N,3),8,'E','s','S','U');
Now i want to manipulate this further, and for that i want to create an equivalent matrix where the colors are replaced by the equivalent index in Palette.
So if Palette is thus: [0 0 0 126 126 72 255 255 255 76 67 65] i want to compare the colours in image with the palette and if a match is found (+- 5) i want to replace it the index in the Palette array, so if black is found i will put 1 (0,0,0) in the image array. Thanks for looking
2 commentaires
Delvin
le 20 Avr 2013
Image Analyst
le 20 Avr 2013
Try mean shift - see my comment below.
Réponses (1)
Image Analyst
le 20 Avr 2013
0 votes
Not sure I understand exactly what you want to do, but it might be able to be done by either intlut() or ind2rgb(). I don't have the stats toolbox, so what is Palette? Is that your classified image?
3 commentaires
Image Analyst
le 20 Avr 2013
You might also want to look at the Color Frequency Image - a sort of histogram image that says how often colors show up. Maybe you could use kmeans on that. http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image
Or else look at this demo: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html
Delvin
le 20 Avr 2013
Image Analyst
le 20 Avr 2013
Modifié(e) : Image Analyst
le 20 Avr 2013
Try this:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
clearvars;
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get an estimate on colors.
[indexedImage, bestColorMap] = rgb2ind(rgbImage, 8);
% Tranform back to an rgbImage.
rgbImageQuantized = ind2rgb(indexedImage, bestColorMap);
% Display the original color image.
subplot(2, 2, 2);
imshow(rgbImageQuantized);
title('Quantized Color Image', 'FontSize', fontSize);
Or you can try mean shift clustering, like in this page: http://machinethatsees.blogspot.com/2012/01/mean-shift-clustering-segmentation-in.html
Catégories
En savoir plus sur k-Means and k-Medoids Clustering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!