if size(im.shape)==3: for i in range(int(dim/2),w-int(dim/2)): for j in range(int(dim/2),h-int(dim/2)): for m in range(-int(dim/2),-int(dim/2)+int(dim)): for n in range(-int(dim / 2), -int(dim / 2) + int(dim)): b.append(im[i+m,j+n,0]) g.append(im[i+m,j+n,1]) r.append(im[i+m,j+n,2]) img[i,j,0]=sum(np.multiply(np.array(a),np.array(b)))/A img[i, j, 1] =sum(np.multiply(np.array(a),np.array(g)))/A img[i, j, 2] =sum(np.multiply(np.array(a),np.array(r)))/A b=[];g=[];r=[] else: for i in range(int(dim/2),w-int(dim/2)): for j in range(int(dim/2),h-int(dim/2)): for m in range(-int(dim/2),-int(dim/2)+int(dim)): for n in range(-int(dim / 2), -int(dim / 2) + int(dim)): b.append(im[i+m,j+n]) img[i,j]=sum(np.multiply(np.array(a),np.array(b)))/A b=[] return img 改成只对灰度图像处理的代码
时间: 2024-04-27 17:24:52 浏览: 146
灰度图像基本处理
4星 · 用户满意度95%
if len(im.shape)==2:
for i in range(int(dim/2),w-int(dim/2)):
for j in range(int(dim/2),h-int(dim/2)):
for m in range(-int(dim/2),-int(dim/2)+int(dim)):
for n in range(-int(dim / 2), -int(dim / 2) + int(dim)):
b.append(im[i+m,j+n])
img[i,j]=sum(np.multiply(np.array(a),np.array(b)))/A
b=[]
return img
阅读全文