ASIPPract4December28,2021[1]:#AdvancedSignalandImageProcessingPractical#CodecompiledandrunbyR.K.Maurya#Credittooriginalauthorsandprogrammers.#Formorelearningresourcesvisithttps://www.rajeshmaurya.in[2]:#Writeaprogramtoapplyvariousimageenhancementusingimagederivativesby,implementingGradientandLaplacianoperations[3]:#%matplotlibinlineimportnumpyasnpfromscipyimportsignal,misc,ndimagefromskimageimportfilters,feature,img_as_floatfromskimage.ioimportimreadfromskimage.colorimportrgb2grayfromPILimportImage,ImageFilterimportmatplotlib.pylabaspylab[4]:#Derivativesandgradientsdefplot_image(image,title):pylab.imshow(image),pylab.title(title,size=20),pylab.axis('off')ker_x=[[-1,1]]ker_y=[[-1],[1]]im=rgb2gray(imread('images/rkm.jpg'))im_x=signal.convolve2d(im,ker_x,mode='same')im_y=signal.convolve2d(im,ker_y,mode='same')im_mag=np.sqrt(im_x**2+im_y**2)im_dir=np.arctan(im_y/im_x)pylab.gray()pylab.figure(figsize=(30,20))pylab.subplot(231),plot_image(im,'original'),pylab.subplot(232),plot_image(im_x,'grad_x')pylab.subplot(233),plot_image(im_y,'grad_y'),pylab.subplot(234),plot_image(im_mag,'||grad||')pylab.subplot(235),plot_image(im_dir,r'$\theta$'),pylab.subplot(236)pylab.plot(range(im.shape[1]),im[0,:],'b-',label=r'$f(x,y)|_{x=0}$',,linewidth=5)1
pylab.plot(range(im.shape[1]),im_x[0,:],'r-',label=r'$grad_x,(f(x,y))|_{x=0}$')pylab.title(r'$grad_x(f(x,y))|_{x=0}$',size=30)pylab.legend(prop={'size':20})pylab.show()<ipython-input-4-61cf5ee046bc>:11:RuntimeWarning:dividebyzeroencounteredintrue_divideim_dir=np.arctan(im_y/im_x)<ipython-input-4-61cf5ee046bc>:11:RuntimeWarning:invalidvalueencounteredintrue_divideim_dir=np.arctan(im_y/im_x)<Figuresize432x288with0Axes>