ASIPPract3-IntensityTransformDecember27,2021[]:#pract3IntensityTransformations(pixeltransformations)[1]:importnumpyasnpfromskimageimportdata,img_as_float,img_as_ubyte,exposure,io,colorfromskimage.ioimportimreadfromskimage.exposureimportcumulative_distributionfromskimage.restorationimportdenoise_bilateral,denoise_nl_means,,estimate_sigma#fromskimage.measureimportcompare_psnrfromskimage.utilimportrandom_noisefromskimage.colorimportrgb2grayfromPILimportImage,ImageEnhance,ImageFilterfromscipyimportndimage,miscimportmatplotlib.pylabaspylab[9]:#loadimageandplothistogram#functiontodisplayimagedefplot_image(image,title=""):pylab.title(title,size=20),pylab.imshow(image)pylab.axis('off')#functiontodisplayhistogramdefplot_hist(r,g,b,title=''):r,g,b=img_as_ubyte(r),img_as_ubyte(g),img_as_ubyte(b)pylab.hist(np.array(r).ravel(),bins=256,range=(0,256),color='r',alpha=0.5)pylab.hist(np.array(g).ravel(),bins=256,range=(0,256),color='g',alpha=0.5)pylab.hist(np.array(b).ravel(),bins=256,range=(0,256),color='b',alpha=0.5)pylab.xlabel('PixelValues',size=20),pylab.ylabel('Frequency',size=20)pylab.title(title,size=20)im=Image.open('images/elephant2.jpeg')im_r,im_g,im_b=im.split()pylab.style.use('ggplot')pylab.figure(figsize=(15,5))pylab.subplot(121),plot_image(im,'OriginalImage')pylab.subplot(122),plot_hist(im_r,im_g,im_b,'HistpgramofRGBImage')pylab.show()1
[11]:#logtransformationim=im.point(lambdai:255*np.log(1+i/255))im_r,im_g,im_b=im.split()pylab.style.use('ggplot')pylab.figure(figsize=(15,5))pylab.subplot(121),plot_image(im,'ImageafterLogTransformation')pylab.subplot(122),plot_hist(im_r,im_g,im_b,'HistogramofLogtransformforRGB,channel')pylab.show()[24]:#powerlawtransformim=img_as_float(imread('images/bird.jpg'))#im_r,im_g,im_b=im.split()gamma=2.5im1=im**gamma2
pylab.style.use('ggplot')pylab.figure(figsize=(15,5))pylab.subplot(121),plot_hist(im[...,0],im[...,1],im[...,2],'HistogramforRGB,channel(Input)')pylab.subplot(122),plot_hist(im1[...,0],im1[...,1],im1[...,2],'Histogramfor,RGBOutput')pylab.show()pylab.figure(figsize=(15,5))pylab.subplot(121),plot_image(im,'Imageoriginal')pylab.subplot(122),plot_image(im1,'Output')pylab.show()