필터 지우기
필터 지우기

Comparing colors against Palette

조회 수: 1 (최근 30일)
Delvin
Delvin 2013년 4월 20일
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
Delvin
Delvin 2013년 4월 20일
let me try to explain in detail: my aim is: take a basic low-res image and retrieve the colours used in in this image into an array called Palette (From the [~, Palette] command above we see Palette contains 8 colours). Now i want an matlab matrix which maps the image, i.e. something ismilar to ascii art except the characters used to draw the image are the indices of the original colouring which is stored in the Palette array,
so if there was a black cell, it would be replaced by the index where 0,0,0 is held in the Palette array.
Hope that helps?
Image Analyst
Image Analyst 2013년 4월 20일
Try mean shift - see my comment below.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 4월 20일
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
Delvin
Delvin 2013년 4월 20일
let me try to explain in detail: my aim is: take a basic low-res image and retrieve the colours used in in this image into an array called Palette (From the [~, Palette] command above we see Palette contains 8 colours). Now i want an matlab matrix which maps the image, i.e. something ismilar to ascii art except the characters used to draw the image are the indices of the original colouring which is stored in the Palette array,
so if there was a black cell, it would be replaced by the index where 0,0,0 is held in the Palette array.
Hope that helps?
Image Analyst
Image Analyst 2013년 4월 20일
편집: Image Analyst 2013년 4월 20일
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);

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by