Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.23 KB | None | 0 0
  1. % Conversão de cores pra HSV
  2.  
  3. imagem = imread('matlab.jpg');
  4. [l, c, p] = size(imagem);
  5.  
  6. for i = 1:l
  7.     for j = 1:c
  8.         red = double(imagem(i,j,1));
  9.         green = double(imagem(i,j,2));
  10.         blue = double(imagem(i,j,3));
  11.                
  12.        
  13.         maxV = max([red green blue]); % Valor maximo em cada iteração
  14.         minV = min([red green blue]); % Valor mmínimo em cada iteração
  15.        
  16.         if maxV == minV
  17.           h =  0;
  18.         else    
  19.            
  20.           % Para compor o "H"
  21.           if(maxV == red && green >= blue)
  22.             h = 60*((green - blue) / (maxV - minV)) + 0;
  23.           elseif(maxV == red && green < blue)
  24.             h = 60*((green - blue) / (maxV - minV)) + 360;
  25.           elseif(maxV == green)
  26.             h = 60*((blue - red)/ (maxV - minV)) + 120;
  27.           elseif(maxV == blue)
  28.             h = 60*((red - green) / (maxV - minV)) + 240;
  29.           end
  30.         end      
  31.  
  32.           % Para compor o "S"
  33.           s = (maxV - minV) / maxV;
  34.        
  35.           % Para compor o V
  36.           v = maxV;
  37.          
  38.           imagem_hsv(i,j,1) = h;
  39.           imagem_hsv(i,j,2) = s;
  40.           imagem_hsv(i,j,3) = v;
  41.          
  42.       end
  43.  end
  44.  
  45. %imagem = rgb2hsv(imagem);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement