def gaussianblur(img,sigma):
if(sigma<0):
print("SIGMA SHOULD BE POSITIVE")
return;
高斯函数
deno=(((math.sqrt(2*3.142*sigma*sigma))))
k=[0,0,0,0,0]
sum=0
for x in range(-2,3):
numo=(math.exp(-((x*x)/(2*(sigma*sigma)))))
k[x+2]=(numo/deno)
sum=sum+k[x+2]
for x in range(0,5):
k[x]=(k[x]/sum)
用g(x)=(1 / squareroot(2 * sigma * sigma * 3.142))计算1维核心* e ^( - (x * x)/(2 * sigma * sigma))
for i in range(0,img.shape[0]):
for j in range(2,img.shape[1]-2):
img[i,j]=abs((img[i,j-2]*k[0])+(img[i,j-1]*k[1])+(img[i,j]*k[2])+(img[i,j+1]*k[3])+(img[i,j+2]*k[4]))
return img; `#end of gaussian blur function`
逐行应用卷积
dog=img = cv2.imread('art.jpg',cv2.IMREAD_GRAYSCALE)
主要功能开始
阅读图片
temp=img=gaussianblur(img,1)
#display image
cv2.imshow('blur1',img)
应用第一次模糊
temp=gaussianblur(temp,1)
cv2.imshow('blur2',temp)
应用第二次模糊
for i in range(0,img.shape[0]):
for j in range(0,img.shape[1]):
dog[i,j]=abs((img[i,j])-(temp[i,j]))
cv2.imshow('DoG',dog)
高斯的差异
gfortran
输出
答案 0 :(得分:1)
您在此处覆盖您的输入:
CATransform3DRotate(t:angle:x:y:z:)
尝试将结果写入新图像。
我不知道OpenCV python界面是如何工作的,var t = CATransform3DMakeRotation(CGFloat(M_PI), 0, 1, 0)
t.m34 = 0.001 // set a 3D perspective to simulate real flipping
let anim = CABasicAnimation(keyPath: "transform")
anim.byValue = NSValue(caTransform3D: t)
anim.duration = 3
anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
anim.fillMode = kCAFillModeForwards
anim.isRemovedOnCompletion = true
let cardContainer = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 100))
cardContainer.backgroundColor = UIColor.clear
// layer1: front side of the card
let layer1 = CALayer()
layer1.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
layer1.backgroundColor = UIColor.red.cgColor
layer1.isDoubleSided = false
// layer2: back side of the card
let layer2 = CALayer()
layer2.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
layer2.backgroundColor = UIColor.blue.cgColor
layer2.isDoubleSided = false
layer2.transform = CATransform3DMakeRotation(CGFloat(M_PI), 0, 1, 0)
cardContainer.layer.addSublayer(layer1)
cardContainer.layer.addSublayer(layer2)
layer1.add(anim, forKey: "anim1")
layer2.add(anim, forKey: "anim2")
会导致for i in range(0,img.shape[0]):
for j in range(2,img.shape[1]-2):
img[i,j]=abs((img[i,j-2]*k[0])+(img[i,j-1]*k[1])+(img[i,j]*k[2])+(img[i,j+1]*k[3])+(img[i,j+2]*k[4]))
与temp=img
共享数据(例如,当您更改数据时,您也会更改另一个)?确保您有两个不同的数据块!