Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [Out]=RGB2HSV(In)
- [h,w,d]=size(In);
- HSV=zeros(h,w,d);
- for i=1:h
- for j=1:w
- RGBmax=double(max(In(i,j,:)));
- RGBmin=double(min(In(i,j,:)));
- HSV(i,j,3)=RGBmax; // WYZNACZAMY V
- if HSV(i,j,3)==0 then
- HSV(i,j,1)=0; // jesli V=0
- HSV(i,j,2)=0; // to H=0 i S=0
- else
- R=double(In(i,j,1))/HSV(i,j,3);
- G=double(In(i,j,2))/HSV(i,j,3);
- B=double(In(i,j,3))/HSV(i,j,3);
- RGBmax=max([R G B]);
- RGBmin=min([R G B]);
- HSV(i,j,2)=RGBmax-RGBmin; // WYZNACZAMY S
- if HSV(i,j,2)==0 then
- HSV(i,j,1)=0; // jesli S=0, to H=0
- else
- R=(R-RGBmin)/(RGBmax-RGBmin); // wykonujemy
- G=(G-RGBmin)/(RGBmax-RGBmin); // normalizacje
- B=(B-RGBmin)/(RGBmax-RGBmin); // skladowych RGB
- RGBmax=max([R G B]);
- RGBmin=min([R G B]);
- if RGBmax==R then // WYZNACZAMY SKLADOWA H
- HSV(i,j,1)=0+60*(G-B);
- if HSV(i,j,1)<0 then
- HSV(i,j,1)=HSV(i,j,1)+360;
- end
- elseif RGBmax==G
- HSV(i,j,1)=120+60*(B-R);
- else
- HSV(i,j,1)=240+60*(R-G);
- end
- end
- end
- end
- printf("%d\n", double(i/h)*100);
- end
- Out=HSV;
- endfunction
- function [Out]=negatyw(In)
- for i=1:256
- LUT(i)=256-i;
- end
- In(:,:)=LUT(In(:,:));
- Out=In;
- endfunction
- global IPD_PATH;
- RGB=ReadImage(IPD_PATH + 'demos\teaset.png');
- //ShowColorImage(RGB, "Obraz");
- //R=RGB(:,:,1);
- //G=RGB(:,:,2);
- //nG=negatyw(G);
- //B=RGB(:,:,3);
- //nB=negatyw(B);
- //
- //R=double(R)/256;
- //nG=double(nG)/256;
- //nB=double(nB)/256;
- //
- //M=R.*nG.*nB;
- //M=uint8(M*256);
- //
- //M=SegmentByThreshold(M,80);
- //figure();
- //ShowImage(R, "czerwona");
- //figure();
- //ShowImage(G, "zielona");
- //figure();
- //ShowImage(B, "niebieska");
- //ShowImage(M, "maska zlozenia");
- tempRGB=zeros(1,1,3); // obrazek testowy - 1 piksel RGB
- tempRGB(1,1,1)=double(0.4392157);
- tempRGB(1,1,2)=double(0.6745098);
- tempRGB(1,1,3)=double(0.71372549);
- M=RGB2HSV(tempRGB);
Add Comment
Please, Sign In to add comment