cv2.imwrite()的怪异行为>> [

问题描述 投票:0回答:1
我正在尝试拍摄图像,通过应用滤镜使其模糊,观察其DFT光谱并保存模糊的图像。我在DFT频谱中观察到了奇怪的响应。我做了以下]

方法-1:

1。图像模糊化

2。在不保存图像的情况下,使用DFT观察其光谱

方法2:

1。图像模糊化

2。保存模糊图像

3。使用cv2.imread读取图像

4。观察DFT并观察其光谱

这两种方法都导致光谱略有不同。

输入图像

the input image

第一种方法中的DFT频谱

the DFT spectrum in first method

方法2中的DFT频谱

the DFT spectrum in method 2

我使用的代码如下

import cv2 import numpy as np import math img=cv2.imread("images/1.jpg") cv2.imshow("car",img) cv2.waitKey() sz=65 d=60 kern=np.zeros((sz,sz)) cX,cY=int(sz/2),int(sz/2) kern=cv2.ellipse(kern,(cX,cY),(0,int(math.ceil(d/2))),45,0,360,(255,255,255),-1)#kernel for generating blur kern=kern/kern.sum() blur=cv2.filter2D(img,-1,kern) cv2.imshow("blur",blur) cv2.waitKey() cv2.destroyAllWindows() cv2.imwrite("images/1 45 60 blur.jpg",blur)##storing the blurred image blur=cv2.imread("images/1 45 60 blur.jpg")##again reading the blurred image-Method 2, in method -1 this line is commented out b,g,r=cv2.split(blur) ##start of dft calculation planes=[np.float32(b),np.zeros(b.shape,np.float32)] complexI=cv2.merge(planes) cv2.dft(complexI,complexI) cv2.split(complexI,planes) cv2.magnitude(planes[0],planes[1],planes[0]) magnitude=planes[0] mat=np.ones(magnitude.shape,dtype=magnitude.dtype) cv2.add(magnitude,mat) cv2.log(magnitude,magnitude) magnitude=np.fft.fftshift(magnitude) cv2.normalize(magnitude,magnitude,0,1,cv2.NORM_MINMAX) cv2.imshow("magnitude",magnitude) cv2.waitKey() cv2.destroyAllWindows()

为什么光谱在保存并重新读取后会发生变化? imread或imwrite函数会更改其属性吗?

我正在尝试拍摄图像,通过应用滤镜使其模糊,观察其DFT光谱并保存模糊的图像。我在DFT频谱中观察到了奇怪的响应。我执行了以下方法-1:1 ....

python opencv image-processing dft
1个回答
0
投票
如果我将其另存为jpg格式,则会得到这种差异,但是当我将其另存为png格式时,将会得到相同的输出。将其另存为jpg格式和png格式时会发生什么?
© www.soinside.com 2019 - 2024. All rights reserved.