Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Artificial Intelligence
EXPERIMENT NO. 01
Title: - To learn ho( to select coins fro) groins* Objective: + To learn ho( to select coins fro) ,ifferent coins in atla-* It.s si)/le atla- /rogra) (hich selects an, ,is/lay a single circle of an original coin* (I) Co pete!cy "#ill: + generic & hence shoul, -e re/eate, in se0eral e1/eri)ents* (II) E$pe%i e!t Objective: 2* To learn -asic 0aria-les ,eclaration in ata- for Artificial Intelligence an, co)/uter 0isions* 3* To learn ho( o-4ects (ill -e selecte, in atla-* 5* &on0ert intensity i)age to -inary i)age* (III) T&eo%etic'l ('c#)%o*!d: + 1-+i,io!.-*tot&%e,&olde%: &on0ert intensity i)ages to -inary i)ages* Autothreshol,ing uses Otsu6s )etho,7 (hich ,eter)ines the threshol, -y s/litting the histogra) of the in/ut i)age to )ini)i8e the 0ariance for each of the /i1el grou/s* "y!t'$: ./ vi,io!.-*tot&%e,&olde% %et*%!, ' "y,te object0 .0 t&'t '*to 'tic'lly co!ve%t, '! i!te!,ity i ')e to ' bi!'%y i ')e. -l)o%it& : This o-4ect i)/le)ents the algorith)7 in/uts7 an, out/uts ,escri-e, in the Autothreshol, u/co)ing e1a)/le* The o-4ect /ro/erties corres/on, to the -loc9 /ara)eters7 e1ce/t: 'ou can only s/ecify a 0alue of Ignore or Saturate for the In/utRange;iolationAction /ro/erty of the Syste) o-4ect* The o-4ect ,oes not su//ort the Error an, <arn an, Saturate o/tions that the corres/on,ing (hen ,ata range is e1cee,e, -loc9 /ara)eter offers* E$' ple:
>>X=imread('peppers.png'); >>imshow(X); >>img = im2single(rgb2gray(imread('peppers.png'))); >>figure, imshow(img); >>hautoth = vision. utothresholder; >>bin = step(hautoth,img); >>pause(2); >>figure;imshow(bin);
1-"tep : Play 0i,eo or i)age se=uence* "y!t'$: ,tep(.0I) "escri/tion: ste/(>7I) sen,s one fra)e of a )ulti,i)ensional 0i,eo I7 or i)age se=uence to the 0i,eo /layer* 2-3i!d(): The fin, function ,eter)ines the in,ices of array ele)ents that )eet a gi0en logical con,ition* In its si)/lest for)7 fin, returns a colu)n 0ector of in,ices* Trans/ose that 0ector to o-tain a ro( 0ector of in,ices* (I+) M'tl'b E$pe%i e!t Code: ! sele"ting "oin from goins hautoth = vision. utothresholder; hboundtra"e = vision.#oundary$ra"er; ! %ead in the image & = imread('"oins.png'); imshow(&); ! othresholding to binari'e the image. bw = step(hautoth,&); ! (erive the start points )row, "ol*= find(bw,+); startpts = )row,2;"ol*; ! (etermine the boundaries y = step(hboundtra"e,bw,startpts); y(y == -) = )*; ! (isplay the results figure, imshow(bw); hold('on'); plot(y(2.2.end,.)/+,y(+.2.end, .)/+,'r','0inewidth',2);
(+II) P%oced*%e: 2* <rite a /rogra) as /er )entione, in the la-* 3* &trlA! for ne( atla- /rogra)* 5* FB for co)/ilation an, e1ecution* @* Re=uire, i)age is as follo(s* B* Follo(ing is the )ain )enu of atla-*
(+III) Ob,e%v'tio! o% C'lc*l'tio!,: 2* Ty/e your o-ser0ation CDDDDDDDDDDD* 3* ############################################################################### ############################################################################### ############################################################################### ############################################################################### Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI) CONC65"ION: -
(XII) E$pe%i e!t Rel'ted 7*e.2* "efine the follo(ing ter)s an, (rite your ans(ers in o-ser0ation* vi,io!.-*tot&%e,&olde%8 vi,io!.(o*!d'%yT%'ce%8 i %e'd()8i ,&o9()8,tep()8 :i!d()8:i)*%e8 plot()8 &old(;o!;)8 3* "efine co)/uter 0ision* 5* <hy (e use i)ages in co)/uter 0isionEArtificial Intelligence* (XIII) -,,e,, e!t:S*!o* E1/eri)ent a1* ar9 O-taine, Process 2 3 Sa)/le co,e Algorith) 3 3 Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI+)De,i%ed O*tp*t:-
e!t Code: -
! 1tep +. %ead 2mage ! %ead in pills3et".png. %4# = imread('pillset".png'); imshow(%4#); ! 1tep 2. $hreshold the 2mage
(+I) P%ec'*tio!,: B* F* ?* M*
It.s case sensiti0e soft(are* For scri/ting use &trlA! an, for ren,ering /ress FB* Se)i colon is necessary after each line -ut not in the )i,,le of the loo/* &trlAR is use, for co))ents*
(+III) Ob,e%v'tio! o% C'lc*l'tio!,: 5* Ty/e your o-ser0ation CDDDDDDDDDDD* @* ############################################################################### ############################################################################### ############################################################################### ############################################################################### Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI) CONC65"ION: -
(XII) E$pe%i e!t Rel'ted 7*e,tio!,. @* "efine the follo(ing ter)s an, (rite your ans(ers in o-ser0ation or in Oui8* vi,io!.-*tot&%e,&olde%8 vi,io!.(o*!d'%yT%'ce%8 i %e'd()8i ,&o9()8,tep()8 :i!d()8:i)*%e8 plot()8 &old(;o!;)8 %)b1)%'y()8)%'yt&%e,&()8 i 1b9()8 b9'%e'ope!()8 ,t%el()8 i clo,e()8i :ill()8b9bo*!d'%ie,()8l'bel1%)b()8%e)io!p%op,()8 B* "efine co)/uter 0ision* F* <hy (e use i)ages in co)/uter 0isionEArtificial Intelligence* (XIII) -,,e,, e!t:S*!o* E1/eri)ent a1* ar9 O-taine, Process 2 3 Sa)/le co,e Algorith) 3 3 Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI+)De,i%ed O*tp*t:-
!1tep + 2 = imread('"ell.tif'); figure, imshow(2), title('original image'); te&t(si'e(2,2),si'e(2,+)/+?, ... 'Krostate "an"er "ell', ... '<ont1i'e',L,'Mori'ontal lignment','right'); te&t(si'e(2,2),si'e(2,+)/2?, .... ' dnan 5omputer Nision', ... '<ont1i'e',L,'Mori'ontal lignment','right');
! 1tep2 )O, threshold* = edge(2, 'sobel'); fudge<a"tor = .?; #Bs = edge(2,'sobel', threshold D fudge<a"tor); figure, imshow(#Bs), title('binary gradient mas6'); seH- = strel('line', 7, H-); se- = strel('line', 7, -); #Bsdil = imdilate(#Bs, )seH- se-*); figure, imshow(#Bsdil), title('dilated gradient mas6');
!1tep ; #Bdfill = imfill(#Bsdil, 'holes'); figure, imshow(#Bdfill); title('binary image with filled holes');
!1tep P se( = strel('diamond',+); #Bfinal = imerode(#Bnobord,se(); #Bfinal = imerode(#Bfinal,se(); figure, imshow(#Bfinal), title('segmented image');
!1tep L #Boutline = bwperim(#Bfinal); 1egout = 2; 1egout(#Boutline) = 2??; figure, imshow(1egout), title('outlined original image');
e!t Code: -
!1tep + 2 = imread('"ell.tif'); figure, imshow(2), title('original image'); te&t(si'e(2,2),si'e(2,+)/+?, ... 'Krostate "an"er "ell', ... '<ont1i'e',L,'Mori'ontal lignment','right'); te&t(si'e(2,2),si'e(2,+)/2?, .... ' dnan 5omputer Nision', ... '<ont1i'e',L,'Mori'ontal lignment','right'); ! 1tep2 )O, threshold* = edge(2, 'sobel'); fudge<a"tor = .?; #Bs = edge(2,'sobel', threshold D fudge<a"tor); figure, imshow(#Bs), title('binary gradient mas6'); seH- = strel('line', 7, H-); se- = strel('line', 7, -); #Bsdil = imdilate(#Bs, )seH- se-*); figure, imshow(#Bsdil), title('dilated gradient mas6'); !1tep ; #Bdfill = imfill(#Bsdil, 'holes'); figure, imshow(#Bdfill); title('binary image with filled holes'); !1tep? #Bnobord = im"learborder(#Bdfill, ;); figure, imshow(#Bnobord), title('"leared border image'); !1tep P se( = strel('diamond',+);
N* It.s case sensiti0e soft(are* 2L*For scri/ting use &trlA! an, for ren,ering /ress FB* 22*Se)i colon is necessary after each line -ut not in the )i,,le of the loo/* 23*&trlAR is use, for co))ents* (+II) P%oced*%e: 22*<rite a /rogra) as /er )entione, in the la-* 23*&trlA! for ne( atla- /rogra)* 25*FB for co)/ilation an, e1ecution* 2@*Re=uire, i)age is as follo(s* 2B*Follo(ing is the )ain )enu of atla-*
(+III) Ob,e%v'tio! o% C'lc*l'tio!,: B* Ty/e your o-ser0ation CDDDDDDDDDDD* F* ############################################################################### ############################################################################### Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI) CONC65"ION: -
(XII) E$pe%i e!t Rel'ted 7*e,tio!,. ?* "efine the follo(ing ter)s an, (rite your ans(ers in o-ser0ation or in Oui8* :*d)e3'cto% 0 ed)e 0 ,t%el() 0 i dil'te() 0 i :ill()0 i cle'%bo%de%() 0 i e%ode()0 b9pe%i () 0 ,e)o*t() M* "efine co)/uter 0ision* N* <hy (e use i)ages in co)/uter 0isionEArtificial Intelligence* (XIII) -,,e,, e!t:S*!o* E1/eri)ent a1* ar9 O-taine, Process 2 3 Sa)/le co,e Algorith) 3 3 Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI+)De,i%ed O*tp*t:-
e!t Code: -
! 1tep +. 5reate 1yntheti" 2mage ! 5reate a grays"ale image that "ontains some distin"t regions. 2 = props1ynthesi'e2mage; imshow(2) title('1yntheti" 2mage'); ! 1tep 2. 5reate a #inary 2mage ! 1egment the grays"ale image by "reating a binary image "ontaining ! the ob:e"ts in the image. #B = 2 > -; figure , imshow(#B) title('#inary 2mage'); ! 1tep 7. 5al"ulate =b:e"t Kroperties 9sing Ki&el Nalues of 4rays"ale ! 2mage.$he regionprops fun"tion supports several properties that "an ! be used with grays"ale images, ! in"luding 'Beighted5entroid', ! 'Jean2ntensity', 'Jin2ntensity', and 'Ja&2ntensity'. ! $hese properties use the original pi&el values of the ob:e"ts for ! their "al"ulations. s = regionprops(#B, 2, @'5entroid','Beighted5entroid'A); ! $o "ompare the weighted "entroid lo"ations with the unweighted ! "entroid lo"ations, display the original image and then, using the ! holdand plot fun"tions, superimpose the "entroids on the image. figure, imshow(2) title('Beighted (red) and 9nweighted (blue) 5entroid 0o"ations'); hold on num=b: = numel(s); for 6 = + . num=b: plot(s(6).Beighted5entroid(+), s(6).Beighted5entroid(2), 'rD'); plot(s(6).5entroid(+), s(6).5entroid(2), 'bo'); end hold off ! 1tep ;. 5al"ulate 5ustom Ki&el Nalue,#ased Kroperties ! Iou "an use the 'Ki&elNalues' property to do "ustom "al"ulations ! based on the pi&el values of the original grays"ale image. ! $he 'Ki&elNalues' property returns ! a ve"tor "ontaining the grays"ale values of pi&els in a region. ! s an e&le, "al"ulate the standard deviation of ea"h region. s = regionprops(#B, 2, @'5entroid','Ki&elNalues','#ounding#o&'A); figure, imshow(2); title('1tandard (eviation of %egions'); hold on for 6 = + . num=b: s(6).1tandard(eviation = std(double(s(6).Ki&elNalues)); te&t(s(6).5entroid(+),s(6).5entroid(2), ...
25*It.s case sensiti0e soft(are* 2@*For scri/ting use &trlA! an, for ren,ering /ress FB* 2B*Se)i colon is necessary after each line -ut not in the )i,,le of the loo/* 2F*&trlAR is use, for co))ents* (+II) P%oced*%e: 2F*<rite a /rogra) as /er )entione, in the la-* 2?*&trlA! for ne( atla- /rogra)* 2M*FB for co)/ilation an, e1ecution* 2N*Re=uire, i)age is as follo(s* 3L*Follo(ing is the )ain )enu of atla-* (+III) Ob,e%v'tio! o% C'lc*l'tio!,: ?* Ty/e your o-ser0ation CDDDDDDDDDDD* M* ############################################################################### ############################################################################### ############################################################################### ############################################################################### #### (IX) Re,*lt: ?* Stu,ent )ust ty/e the result or out/ut of the /rogra)CDDDDDDDDDDDDDD** M* ################################################################################### #####################################################################* Developed by:Adnan Alam
Khan(Write2adnanalamkhan@gmail.com)
(XI) CONC65"ION: -
(XII) E$pe%i e!t Rel'ted 7*e,tio!,. 2L*"efine the follo(ing ter)s an, (rite your ans(ers in o-ser0ation or in Oui8* :*d)e3'cto% 0 ed)e 0 ,t%el() 0 i dil'te() 0 i :ill()0 i cle'%bo%de%() 0 i e%ode()0 b9pe%i () 0 ,e)o*t() 22*"efine co)/uter 0ision* 23*<hy (e use i)ages in co)/uter 0isionEArtificial Intelligence* (XIII) -,,e,, e!t:S*!o* E1/eri)ent a1* ar9 O-taine, Process 2 3 5 @ B Sa)/le co,e Algorith) Flo( chart Synta1 Tea) Lea,ershi/ 3 3 3 3 3
(XI+)De,i%ed O*tp*t:-