speedup for-loops by bsxfun?

조회 수: 3 (최근 30일)
BY H
BY H 2021년 8월 10일
댓글: Stephen23 2021년 8월 11일
Is any solution to speedup my following code?
Supposed I have an RGB image, for each pixel, I want to find the closest color in given palette (k colors) for quantization.
PALETTE = [c1R, c1G, c1B; ....; ckR, ckG, ckB];
for i = 1:size(img,1)
for j = 1:size(img,2)
% find the closest color from PALETTE
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2021년 8월 11일
rgb2ind() does that, at least for some definition of "closest". You need to be specific about how you want to compute "closest" when it comes to colour.
If the task is to quantize the colors, then
Q = reshape(PALETTE(rgb2ind(YourImage, PALETTE),:),size(YourImage));
  댓글 수: 1
Stephen23
Stephen23 2021년 8월 11일
'...at least for some definition of "closest" '
Just not a very perceptual one: https://en.wikipedia.org/wiki/Color_difference

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

카테고리

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