HSI<--->RGB |
|
lovepage1212
一般會員 發表:4 回覆:1 積分:1 註冊:2007-04-12 發送簡訊給我 |
//---------------rgb to hsi--------------------------
for i := 0 to py-1 do begin for j := 0 to px-1 do begin if (rgbmap[i,j].R rgbmap[i,j].G rgbmap[i,j].B)=0 then begin _r:=0; _g:=0;_b:=0; end else begin _r:= rgbmap[i,j].R * power((rgbmap[i,j].R rgbmap[i,j].G rgbmap[i,j].B),-1); _g:= rgbmap[i,j].G * power((rgbmap[i,j].R rgbmap[i,j].G rgbmap[i,j].B),-1); _b:= rgbmap[i,j].B * power((rgbmap[i,j].R rgbmap[i,j].G rgbmap[i,j].B),-1); end; //-----------i------------------------- hsimap[i,j].I:=(rgbmap[i,j].R rgbmap[i,j].G rgbmap[i,j].B) *0.3333; //-----------s-------------------------- hsimap[i,j].S:=(1-min(min(_b,_r),_g)*3)*100; //-----------h--------------------------- if ((_r*_r) (_g*_g) (_b*_b)-(_r*_g)-(_r*_b)-(_b*_g))=0 then //分母不=0 begin if _b>_g then begin hsimap[i,j].H:=270; end ; if _b<_g then begin hsimap[i,j].H:=90; end ; end else begin if _b>_g then begin hsimap[i,j].H:=360-arcCos((2*_r-_g-_b)*0.5*power(sqrt(((_r*_r) (_g*_g) (_b*_b)-(_r*_g)-(_r*_b)-(_b*_g))),-1))*57.29577951; end ; if _b<_g then begin hsimap[i,j].H:=arcCos((2*_r-_g-_b)*0.5*power(sqrt(((_r*_r) (_g*_g) (_b*_b)-(_r*_g)-(_r*_b)-(_b*_g))),-1))*57.29577951; end; if _b=_g then begin if _r>_g then begin hsimap[i,j].H:=0; end else hsimap[i,j].H:=180; end; end; end; end; //---------------hsi to rgb-------------------------- for i := 0 to py-1 do begin for j := 0 to px-1 do begin S:=hsimap[i,j].S*0.01; L:=hsimap[i,j].I*0.003921; if hsimap[i,j].H<120 then begin H:=hsimap[i,j].H*0.01745; x:=L*(1-S); y:=L*(1 (S*cos(H)*power(cos(1.047-H),-1))); z:=3*L-(x y); rgbhsi[i,j].B:=round(255*x) ; rgbhsi[i,j].R:=round(255*y) ; rgbhsi[i,j].G:=round(255*z) ; end else if hsimap[i,j].H<240 then begin H:=(hsimap[i,j].H-120)*0.01745; x:=L*(1-S); y:=L*(1 (S*cos(H)*power(cos(1.047-H),-1))); z:=3*L-(x y); rgbhsi[i,j].R:=round(255*x) ; //4捨5入 rgbhsi[i,j].G:=round(255*y) ; rgbhsi[i,j].B:=round(255*z) ; end else if hsimap[i,j].H<=360 then begin H:=(hsimap[i,j].H-240)*0.01745; x:=L*(1-S); y:=L*(1 (S*cos(H)*power(cos(1.047-H),-1))); z:=3*L-(x y); rgbhsi[i,j].G:=round(255*x) ; rgbhsi[i,j].B:=round(255*y) ; rgbhsi[i,j].R:=round(255*z) ; end; end; end; //--------------------------------------------------- |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |