speedup for-loops by bsxfun?
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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
0 commentaires
Réponses (1)
  Walter Roberson
      
      
 le 11 Août 2021
        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 commentaire
  Stephen23
      
      
 le 11 Août 2021
				'...at least for some definition of "closest" '
Just not a very perceptual one: https://en.wikipedia.org/wiki/Color_difference
Voir également
Catégories
				En savoir plus sur Modify Image Colors dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


