Advertisement
sebihomie

HSV berechnung

Oct 22nd, 2020
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.01 KB | None | 0 0
  1. %HSV new Function
  2. Idouble = im2double(Image);
  3.  
  4. maxrgb = max(Idouble,[],3);
  5. minrgb = min(Idouble,[],3);
  6.  
  7. V = maxrgb;
  8. S = (maxrgb-minrgb)./maxrgb;
  9. H = nan(size(Idouble,1),size(Idouble,2));
  10.  
  11. for i = 1:size(Idouble,1)
  12.     for j = 1:size(Idouble,2)
  13.         if S(i,j) == 0
  14.             delta = maxrgb(i,j) - minrgb(i,j);
  15.            
  16.             if maxrgb(i,j) == Idouble(i,j,1)     %R==max
  17.                 H(i,j) = (Idouble(i,j,2) - Idouble(i,j,3)) / delta;
  18.                
  19.                 elseif maxrgb(i,j) == Idouble(i,j,2)     %G==max
  20.                 H(i,j) = 2 + (Idouble(i,j,2) - Idouble(i,j,3)) / delta;
  21.                
  22.                 elseif maxrgb(i,j) == Idouble(i,j,3)     %B==max
  23.                 H(i,j) = 4 + (Idouble(i,j,2) - Idouble(i,j,3)) / delta;
  24.             end
  25.            
  26.             H(i,j) = H(i,j) * 60;
  27.            
  28.             if H(i,j) < 0
  29.                 H(i,j) = H(i,j) + 360;
  30.             end
  31.         end
  32.     end
  33. end
  34.  
  35. HSV2(:,:,1) = H;
  36. HSV2(:,:,2) = S;
  37. HSV2(:,:,3) = V;
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement