ASIP-Pract-9December28,2021[1]:#AdvancedSignalandImageProcessingPractical#CodecompiledandrunbyR.K.Maurya#Credittooriginalauthorsandprogrammers.#Formorelearningresourcesvisithttps://www.rajeshmaurya.in[2]:#Writetheprogramtoextractimagefeaturesbyimplementingmethodslike,cornerandblobdetectors,HoGandHaarfeatures.[3]:importnumpyasnpfromscipyimportsignal,misc,ndimagefromskimageimportfilters,feature,img_as_floatfromskimage.ioimportimreadfromskimage.colorimportrgb2grayfromPILimportImage,ImageFilterimportmatplotlib.pylabaspylab[4]:#TheLoGandDoGfiltersfromscipy.signalimportconvolve2d#fromscipy.miscimportimreadfromscipy.ndimageimportgaussian_filterfromnumpyimportpidefplot_kernel(kernel,s,name):pylab.imshow(kernel,cmap='YlOrRd')defLOG(k=12,s=3):n=2*k+1#sizeofthekernelkernel=np.zeros((n,n))foriinrange(n):forjinrange(n):kernel[i,j]=-(1-((i-k)**2+(j-k)**2)/(2.*s**2))*np.,exp(-((i-k)**2+(j-k)**2)/(2.*s**2))/(pi*s**4)kernel=np.round(kernel/np.sqrt((kernel**2).sum()),3)returnkerneldefDOG(k=12,s=3):n=2*k+1#sizeofthekernels1,s2=s*np.sqrt(2),s/np.sqrt(2)1
kernel=np.zeros((n,n))foriinrange(n):forjinrange(n):kernel[i,j]=np.exp(-((i-k)**2+(j-k)**2)/(2.*s1**2))/(2*pi*s1**2),-np.exp(-((i-k)**2+(j-k)**2)/(2.*s2**2))/(2*pi*s2**2)kernel=np.round(kernel/np.sqrt((kernel**2).sum()),3)returnkernels=3#sigmavalueforLoGimg=rgb2gray(imread('images/aditya.png'))kernel=LOG()outimg=convolve2d(img,kernel)pylab.figure(figsize=(20,20))pylab.subplot(221),pylab.title('LOGkernel',size=20),plot_kernel(kernel,s,,'DOG')pylab.subplot(222),pylab.title('outputimagewithLOG',size=20)pylab.imshow(np.clip(outimg,0,1),cmap='gray')#clipthepixelvaluesin,between0and1kernel=DOG()outimg=convolve2d(img,DOG())pylab.subplot(223),pylab.title('DOGkernel',size=20),plot_kernel(kernel,s,,'DOG')pylab.subplot(224),pylab.title('outputimagewithDOG',size=20)pylab.imshow(np.clip(outimg,0,1),cmap='gray')pylab.show()<ipython-input-4-ac9a38e6aa19>:30:FutureWarning:NonRGBimageconversionisnowdeprecated.ForRGBAimages,pleaseusergb2gray(rgba2rgb(rgb))instead.Inversion0.19,aValueErrorwillberaisedifinputimagelastdimensionlengthisnot3.img=rgb2gray(imread('images/aditya.png'))2
3