EE 168 Handout #32 Intoduction to Diital Imae Pocessin Mach 7, 2012 HOMEWORK 7 SOLUTIONS Polem 1: Colo Wheels We can epesent an N x N colo imae y a thee-dimensional aay such that the fist two dimensions ae of size N each, and the thid dimension has size 3. The fist two dimensions of the aay ae used to epesent the location of pixels, while the thid is used to stoe the ensities of the thee pimay colos (ed, een, and lue). Fo instance, usin Matla notation, we can wite: a(i, j, 1) = w 1 ; a(i, j, 2) = w 2 ; a(i, j, 3) = w 3 ; This means that the elative ensities of the ed, een, lue components in the i th ow, j th column of the imae a ae w 1, w 2 and w 3, espectively. Accodinly, fo the equal-ensity colo wheel, each cicle in the colo wheel has a weiht of 1 fo only one of the thee colos and a weiht of 0 fo the othe two. By vayin the weihts, we can modify the colo values in the wheel. In the non-ovelappin eions, the chane of weihts causes only an ensity chane, while fo the ovelappin eions, a colo chane is also oseved. These esults ae shown in Fiue 1-1. Note that the RGB colo space is not the only way to epesent colo imaes. One can, altenatively, use othe colo spaces, one of them ein the HSB space. In HSB, H epesents hue, S epesents the satuation, and B epesents the ihtness. The hue dimension povides a compaison of the thee pimay colos (ed, een, and lue) and thei weihted mixtues (usin at most two of the ed, een, o lue at a time). Note that ensities ae assumed to e equal fo all colos in the hue dimension. This is illustated in Fiue 1-2. The Colo Wheel with Equal Intensities The Colo Wheel with Lowe Red Intensity The Colo Wheel with Lowe Geen Intensity The Colo Wheel with Lowe Blue Intensity Fiue 1-1: The Colo Wheel and Weihtin Colos 1
A Hue Map 20 40 60 80 120 140 20 40 60 80 120 140 Fiue 1-2: The Hue Map Polem 2: RGB Imaes We can stetch a colo imae fo a nume of easons, one of them ein that the oveall imae contast is too low to ceate a pleasin display. The colo imae can e stetched y takin the ensity values of the imae as a efeence. The total ensity at location (n, can e computed fom the (ed), (een), and (lue) components like so: I n, m 2 n, m 2 n, m 3 2 n, m We can then stetch the individual colo ensity values of the imae to otain an imae that has a total ensity with a mean of 160 and a standad deviation of 80. We ceate this tansfomation y fist calculatin the mean and standad deviation of the oiinal imae s total ensity. Then the linea tansfomation equation fo the total ensity stetch can e applied to each of the thee colo components, esultin in a pleasin colo imae. Fiue 2-1 compaes the oiinal low-contast imae and the ensity-stetched imae. Fo this paticula imae, the oiinal imae s total ensity has a mean of 47.9 and a standad deviation of 26.3. Hence, the tansfomation equations ae: 80 160 47.9 26.3 80 160 47.9 26.3 80 160 47.9 26.3 2
The oiinal low-contast imae The total-esity stetched imae Fiue 2-1: Usin the Total Intensity to stetch Colo Imaes Polem 3: False Colo Imaes We can stetch a colo imae in two diffeent ways: i) All thee colo components can e stetched usin a common linea tansfomation equation. The common equation may e otained y applyin a stetch on the total ensity values of the imae, as done in the pevious polem. Denotin the mean and the standad deviation of the total ensity imae y m and, espectively, we can otain the colo components usin the followin colo channel tansfomations, whee m and denote the desied mean and standad deviation: m m m m m m ii) Each colo component can e indepently stetched usin a diffeent linea tansfomation equation. This method will maximize the colo space, ut will not peseve the colo alance and will not epesent the tue physical colos. The output colos will now equally eveal the details contained in each colo channel. So featues oiinally hidden in minoity colos will now e enhanced. In this case, each equation is otained y applyin a stetch only on that paticula colo ensity component. Denotin the means and standad deviations of the ed, een, and lue components of the imae as m,, m,, m,, espectively, one can otain the colo components usin the followin linea tansfomations: 3
m m m m m m The Oiinal Imae 700 800 900 0 800 0 Stetchin y a Common Tansfomation Stetchin y Indepent Tansfomations 700 700 800 800 900 900 0 800 0 0 800 0 Fiue 3-1: Convolvin two ectanles of diffeent widths in space and in special-fequency domains 4
Polem 4: Indexed Colo We can use indexin to compess colo infomation in imaes. Fo instance, if a paticula application needs colo imaes that ae shades of only lue, then all its should e used to encode only ensities of lue, and no its should e used to code the ed and een colo components. Fiue 4-1 shows a ay scale imae and its vesion in shades of lue. The fiue also displays the imae with a diffeent colo tale that exts fom lack to white thouh shades and mixtues of een and yellow. The colo map, descied in the polem, can e fomed y: - Vayin the ensity of een fom 0 to 1 as the index inceases fom 0 to, with the ensities of ed and lue held constant at 0. - Vayin the ensity of ed fom 0 to 1 as the index inceases fom to, with the ensity of een held at a constant of 1, and the ensity of lue held at 0. - Vayin the ensity of lue fom 0 to 1 as the index inceases fom to 255, with the ensities of ed and een held constant at 1. The Oiinal B/W Imae 4 5 Fiue 4-1: The Oiinal Black & White Imae The Imae in shades of Blue The Imae usin a Colo Tale Fiue 4-2: Imae Displayed usin diffeent Colo Tales 5
MATLAB code: M=256; Polem 1: Colo Wheels cicle=ones(m+1,m+1); % fom a cicle of diamete M fo i=1:(m+1) fo j=1:(m+1) if((sqt((i-((m/2)+1))^2+(j-((m/2)+1))^2))>m/2) cicle(i,j)=0; % each of the thee dimensions is fo a paticula colo component a=zeos(,,3); % loop thouh vaious weihts on the colo ensities w1 = [1 0.5 1 1]; w2 = [1 1 0.5 1]; w3 = [1 1 1 0.5]; titles = {'Equal Intensities'; 'Lowe Red Intensity'; 'Lowe Geen Intensity'; 'Lowe Blue Intensity'}; count = 1; fiue; fo ind=1:lenth(w1), fo i=1:(m+1) fo j=1:(m+1) a(i+,j+,1)=w1(ind)*cicle(i,j); a(i+,j+,2)=w2(ind)*cicle(i,j); a(i+,j+,3)=w3(ind)*cicle(i,j); suplot(2,2,count); imaesc(a); axis('imae') title(spf('the Colo Wheel with %s', cha(titles(ind)))) count = count+1; % The hue map wheel_adius = 75; fo i=-wheel_adius:wheel_adius fo j=-wheel_adius:wheel_adius [v1,v2]=cat2pol(i,j); a(i+76,j+76)=v1; %theta (i+76,j+76)=ound(v2); %adius % hue vaies with the anle of otation wheel_diam = wheel_adius*2; %= m1 = zeos(wheel_diam,wheel_dia; fo i=1:wheel_diam fo j=1:wheel_diam % nomalize theta to e etween 0 and 1 % all values on wheel with same theta ae set to the same value, theta m1(i,j)=(1/(2*pi))*(a(i,j)+pi); % convesion to the space m2 = zeos(wheel_diam,wheel_diam,3); fo i=1:wheel_diam fo j=1:wheel_diam if((i,j)<wheel_adius), %only fill in wheel cicle 6
% set satuation and ensity to 1 % flip hue ove x-axis so that ed (theta=0) is at top of wheel m2(i,j,:)=hsv2([m1(i,wheel_diam+1-j),1,1]); fiue; imaesc(m2); axis('imae'); title('a Hue Map') Polem 2: RGB Imaes nows = 435; ncols = 580; % ead the imaes f=fopen('la7po2',''); a_ed=fead(f,[ncols nows],'u8'); a_ed=a_ed'; f=fopen('la7po2',''); a_een=fead(f,[ncols nows],'u8'); a_een=a_een'; f=fopen('la7po2',''); a_lue=fead(f,[ncols nows],'u8'); a_lue=a_lue'; a_oi(:,:,1)=a_ed; a_oi(:,:,2)=a_een; a_oi(:,:,3)=a_lue; % compute imae ensity i=(((a_ed.^2)+(a_een.^2)+(a_lue.^2))/3).^.5; % compute the ensity mean and standad deviation fo the stetch mean_i=mean(mean(i)) va_i=(mean((eshape(i,ncols*nows,1)-mean_i).^2)); _i=va_i^.5 % stetch each colo component usin a common tansfomation ased on the total ensity mean_desied = 160; _desied = 80; a = zeos(nows, ncols, 3); a(:,:,1)=(_desied/_i)*(a_ed-mean_i)+mean_desied; a(:,:,2)=(_desied/_i)*(a_een-mean_i)+mean_desied; a(:,:,3)=(_desied/_i)*(a_lue-mean_i)+mean_desied; % check the ensity mean and standad deviation afte the stetch i=(((a(:,:,1).^2)+(a(:,:,2).^2)+(a(:,:,3).^2))/3).^.5; mean_i=mean(mean(i)) va_i=(mean((eshape(i,ncols*nows,1)-mean_i).^2)); _i=va_i^.5 fiue; suplot(1,2,1); imaesc(u8(a_oi)); axis('imae') title('the oiinal low-contast imae') suplot(1,2,2); imaesc(u8(a)); axis('imae') title('the total-esity stetched imae') Polem 3: False Colo Imaes % ead the imaes f=fopen('la7po3',''); 7
a_ed=fead(f,[1024 1024],'u8'); a_ed=a_ed'; f=fopen('la7po3',''); a_een=fead(f,[1024 1024],'u8'); a_een=a_een'; f=fopen('la7po3',''); a_lue=fead(f,[1024 1024],'u8'); a_lue=a_lue'; a_oi(:,:,1)=a_ed; a_oi(:,:,2)=a_een; a_oi(:,:,3)=a_lue; % compute the ensity i=(((a_ed.^2)+(a_een.^2)+(a_lue.^2))/3).^.5; % compute the ensity mean and standad deviation fo the stetch mean_i=mean(mean(i)) va_i=(mean((eshape(i,1024*1024,1)-mean_i).^2)); _i=va_i^.5; mean_desied = 160; _desied = 80; % stetch each colo component usin a common tansfomation a(:,:,1)=(_desied/_i)*(a_ed-mean_i)+mean_desied; a(:,:,2)=(_desied/_i)*(a_een-mean_i)+mean_desied; a(:,:,3)=(_desied/_i)*(a_lue-mean_i)+mean_desied; mean_ed=mean(mean(a_ed)) va_ed=(mean((eshape(a_ed,1024*1024,1)-mean_ed).^2)) _ed=va_ed^.5; mean_een=mean(mean(a_een)) va_een=(mean((eshape(a_een,1024*1024,1)-mean_een).^2)) _een=va_een^.5; mean_lue=mean(mean(a_lue)) va_lue=(mean((eshape(a_lue,1024*1024,1)-mean_lue).^2)) _lue=va_lue^.5; % stetch each colo component usin a diffeent tansfomation (:,:,1)=(_desied/_ed)*(a_ed-mean_ed)+mean_desied; (:,:,2)=(_desied/_een)*(a_een-mean_een)+mean_desied; (:,:,3)=(_desied/_lue)*(a_lue-mean_lue)+mean_desied; fiue; suplot(1,2,1); imaesc(u8(a_oi)); axis('imae') title('the Oiinal Imae') fiue; suplot(1,2,1); imaesc(u8(a)); axis('imae') title('stetchin y a Common Tansfomation') suplot(1,2,2); imaesc(u8()); axis('imae') title('stetchin y Indepent Tansfomations') Polem 4: Indexed Colo nows = 435; ncols = 580; f=fopen('la7po4data',''); im_oi=fead(f,[ncols nows],'u8'); im_oi=im_oi'; im_luish(1:nows,1:ncols,1)=zeos(nows,ncols); im_luish(1:nows,1:ncols,2)=zeos(nows,ncols); im_luish(1:nows,1:ncols,3)=im_oi/255; im_=zeos(nows,ncols,3); % fom a colo tale 8
fo i=1:nows, fo j=1:ncols, if im_oi(i,j)<= im_(i,j,2)=(1/)*im_oi(i,j); if (im_oi(i,j)>)&(im_oi(i,j)<=) im_(i,j,1)=(1/)*(im_oi(i,j)-); im_(i,j,2)=1; if (im_oi(i,j)>=) im_(i,j,1)=1; im_(i,j,2)=1; im_(i,j,3)=(1/55)*(im_oi(i,j)-); fiue; colomap(ay); imaesc(u8(im_oi)); axis('imae') title('the Oiinal B/W Imae') fiue; suplot(1,2,1); imaesc((im_luish)); axis('imae') title('the Imae in shades of Blue') suplot(1,2,2); imaesc((im_)); axis('imae') title('the Imae usin a Colo Tale'); 9