Beispiel #1
0
    return theta
    
img=cv2.imread('pic1.png',0)
w=60
aa=200
bb=100
img=img[aa:aa+w,bb:bb+w]
#img=cv2.equalizeHist(img)
mmin=np.min(img)
mmax=np.max(img)
q=0.2
#img[np.where(img<q*(mmax-mmin))]=0
#img[np.where(img>(1-q)*(mmax-mmin))]=255
img=normalize2(img,125,128)
theta=calcDirection(img)
imshow(img)
img[np.where(img>255)]=255;img[np.where(img<0)]=0
M,N=np.shape(img)
plt.quiver(M/2,N/2,np.cos(theta),np.sin(theta),color='r')

f=np.fft.fft2(img)
f=np.fft.fftshift(f)
fmag = np.abs(f)
#imshow(fmag)
aa=np.where(fmag==np.max(fmag))
fmag[aa]=0; argmax=np.where(fmag==np.max(fmag))
pho_c=((argmax[0][0]-aa[0][0])**2+(argmax[1][0]-aa[1][0])**2)**0.5
N,M=np.shape(img)
nn,mm=np.meshgrid(np.arange(-(N-1)/2.0,(N-1)/2.0+1),np.arange((M-1)/2.0+1,-(M-1)/2.0,-1))
bw=3
pho=(nn**2+mm**2)**0.5
gaussian_block = 5
Vy = cv2.GaussianBlur(Vy, (gaussian_block, gaussian_block), gaussianBlurSigma,
                      gaussianBlurSigma)
Vx = cv2.GaussianBlur(Vx, (gaussian_block, gaussian_block), gaussianBlurSigma,
                      gaussianBlurSigma)
theta = 0.5 * np.arctan2(Vy, Vx)  #+np.pi/2
#theta[np.where(theta>np.pi/2)]-=np.pi
#theta[np.where(theta<=-np.pi/2)]+=np.pi
#theta=0.5*cv2.GaussianBlur(2*theta,(gaussian_block,gaussian_block),1.5)
#theta_filter=convolve2d(theta,h,mode='same')
#theta_small=theta_filter[0:N:w,0:M:w]

#img1=ridgeComp2(img,theta,w)
##img2=ridgeComp(img1,theta,w)
##img2=blockproc(img1,binarize,(32,32))
#img2=binarize2(img1,theta,w)
imgGabor = GaborFilter(img, w, wl, np.pi / 2 - theta)
end = time.clock()
print end - start
X, Y = np.mgrid[0:N:w, 0:M:w]
plt.figure()
plt.subplot(1, 2, 1)
plt.quiver(Y, X, np.cos(theta), np.sin(theta), color='r')
imshow(img)
plt.subplot(1, 2, 2)
imshow(imgGabor)
##currentAxis = plt.gca()
##currentAxis.add_patch(Rectangle((400,96),w,w,fill=None,color='b'))
#plt.figure()#
#img12=np.hstack((img1,img2))
#imshow(img12)
from scipy.signal import convolve2d
import time
from initial import imshow
from initial import normalize2
from initial import block_view
from initial import blockproc
from initial import ridgeComp
from initial import ridgeComp2
from initial import binarize
from initial import binarize2

start = time.clock()
img = cv2.imread('pic2.tif', 0)
blockSize = 16
factor = 0.9
img_block = block_view(img, (blockSize, blockSize))
imgout = np.zeros_like(img)
out_block = block_view(imgout, (blockSize, blockSize))
threshold = np.min(img) + factor * (np.max(img) - np.min(img))
for b, o in zip(img_block, out_block):
    a = np.asarray(map(lambda x: np.mean(x), b))
    a[np.where(a >= threshold)] = 255
    a[np.where(a < threshold)] = 0
    o[:, :] = np.asarray(map(lambda x, y: x * y, np.ones(o.shape), a))

img12 = np.hstack((img, imgout))

end = time.clock()
print end - start
imshow(img12)
Beispiel #4
0
#imgN=img+noise
#imshow(imgN)
#cv2.imwrite('test.jpg',img)
start=time.clock()

img=cv2.imread('pic5.tif',0)
blockSize=16
img,imgfore=init.segmentation(img)
N,M=img.shape
X,Y=np.mgrid[0:N:blockSize,0:M:blockSize]
plt.figure()
plt.subplot(1,3,1)

theta=init.calcDirection(img,blockSize)
plt.quiver(Y,X,np.cos(theta),np.sin(theta),color='r')
imshow(img)
wl=init.calcWl(img,blockSize)
imgR=init.ridgeComp2(img,theta,blockSize)
#imgR=img.copy()
plt.subplot(1,3,2)
imshow(imgR)
#imga=init.inverse(imgR)
imgG=init.GaborFilter(imgR,blockSize,wl,np.pi/2-theta)
imgG[np.where(imgfore==255)]=255
#imgG=init.inverse(imga)
plt.subplot(1,3,3)
imshow(imgG)

end=time.clock()
print end-start
#w=16