def createGifs(imgDir, createGifsOf): #Single usage: utils.createGif(cfg.imgDir+'\\ImgShow\\', img_names ) print 'Creating Gifs' gifPath = imgDir + 'gifs\\' if createGifsOf['original']: originalPath = imgDir if os.path.exists(originalPath): img_names = utils.getListOfImages(originalPath, cfg.imgFormats) utils.createGif(originalPath, img_names, 'original', gifPath) if createGifsOf['translation']: translationPath = imgDir + 'translation' if os.path.exists(translationPath): img_names = utils.getListOfImages(translationPath, cfg.imgFormats) utils.createGif(translationPath, img_names, 'translation', gifPath) if createGifsOf['width']: widthPath = imgDir + 'width' if os.path.exists(widthPath): img_names = utils.getListOfImages(widthPath, cfg.imgFormats) utils.createGif(widthPath, img_names, 'width', gifPath) if createGifsOf['width_hq']: width_hqPath = imgDir + 'width_hq' if os.path.exists(width_hqPath): img_names = utils.getListOfImages(width_hqPath, cfg.imgFormats) utils.createGif(width_hqPath, img_names, 'width_hq', gifPath) if createGifsOf['test']: originalPath = imgDir + 'test' if os.path.exists(originalPath): img_names = utils.getListOfImages(originalPath, cfg.imgFormats) utils.createGif(originalPath, img_names, 'test', gifPath)
def loadFiles(): Imgfolder = cfg.imgDir ImgFileList = utils.getListOfImages(cfg.imgDir, cfg.imgFormats) natsort(ImgFileList) if ImgFileList.__contains__('Thumbs.db'): ImgFileList.remove('Thumbs.db') return ImgFileList, Imgfolder
def run(dir=cfg.imgDir, method='linear'): curve = [] curve.append((0, 0)) time_start = time.time() print 'Translating movement in ', dir onlyImages = utils.getListOfImages(dir, cfg.imgFormats) imgRef = cv2.imread(dir + onlyImages[0]) sift = cv2.SIFT() referenceKp, referenceDes = sift.detectAndCompute(imgRef, None) for i in range(1, len(onlyImages)): curve.append( getInitialCurve(sift, imgRef, referenceKp, referenceDes, dir, onlyImages[i], i, curve)) correctX, correctY = getCurveFromMethod(curve, method) for i in range(0, len(onlyImages)): performCorrection(correctX[i], correctY[i], dir, onlyImages[i]) plt.figure() x = [k[0] for k in curve] y = [k[1] for k in curve] for i in range(0, len(onlyImages)): plt.plot(x, label='x', color='g') plt.plot(y, label='y', color='b') plt.plot(correctX, label='fitx', color='c') plt.plot(correctY, label='fity', color='m') plt.xticks([k for k in range(1, len(x))]) plt.axvline(x=float(i), color='r') plt.grid() plt.legend() append0 = '0' if i >= 10.0: append0 = '' plt.savefig(cfg.imgDir + '\\translation\\' + append0 + str(i) + '.jpg') plt.clf() total_time = time.time() - time_start np.save(dir + '\\translation\\translationX.npy', correctX) np.save(dir + '\\translation\\translationY.npy', correctY) print 'Translating displacement finished, spending time:', total_time print '##############################################################'
from Configuration import Config as cfg from Tools import utils import cv2 import pdb import matplotlib.pyplot as plt img_names = utils.getListOfImages(cfg.imgDir+'BW_resized\\', cfg.imgFormats) imgs = utils.loadAllImages(cfg.imgDir+'BW_resized\\', cfg.imgFormats, False) img = imgs[0] #find first vessel bw_layer = img[:][:][0] k=0 for row in bw_layer: if sum(row)>0: print 'ZES' newRow = row*255 bw_layer[k]=newRow cv2.imshow('image', bw_layer) cv2.waitKey(0) pdb.set_trace() k+=1 laplacian = cv2.Laplacian(img, cv2.CV_64F) sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=5) sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=5)
def justCreateGif(imgDir): if os.path.exists(imgDir): img_names = utils.getListOfImages(imgDir, cfg.imgFormats) print 'got image names' utils.createGif(imgDir, img_names, 'thisGif', imgDir)
from Tools.BGR2RGB import BGR2RGB from Tools.ZoneMarker import zoneMarker from Tools.SortFolder import natsort from Configuration import Config as cfg from Tools import utils """ This program is trying to realize the vessel analysis for Infared Images!! """ ImgNumber = 0 SegMethod = 2 ##Gabor 1 / LineDetector 2 """provide the image folder location""" # Imgfolder = 'Image\\folder\\path\\' Imgfolder = cfg.imgDir ImgFileList = utils.getListOfImages(cfg.imgDir, cfg.imgFormats) natsort(ImgFileList) if ImgFileList.__contains__('Thumbs.db'): ImgFileList.remove('Thumbs.db') "Read a image first: " ImgName = Imgfolder + ImgFileList[ImgNumber] Img0 = cv2.imread(ImgName) print 'Img Name:', ImgNumber, ImgFileList[ImgNumber] """Resize the image""" downsizeRatio = 1 Img_Resized = cv2.resize(Img0, dsize=None, fx=downsizeRatio, fy=downsizeRatio) Mask = np.zeros((Img_Resized.shape[:2]), dtype=np.uint8) Mask[20:-20, 20:-20] = 1 Img = Img_Resized.copy() ##############################################################
bf = cv2.BFMatcher() matches = bf.knnMatch(referenceDes, targetDes, k=2) # Apply ratio test good = [] for m, n in matches: if m.distance < 0.75 * n.distance: # Removed the brackets around m good.append(m) src_pts = np.float32([referenceKp[m.queryIdx].pt for m in good]).reshape(-1, 1, 2) dst_pts = np.float32([targetKp[m.trainIdx].pt for m in good]).reshape(-1, 1, 2) M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) #matchesMask = mask.ravel().tolist() dst = cv2.warpPerspective(imgTarget, inv(M), (1600, 1200)) # plt.subplot(121),plt.imshow(img2),plt.title('Input') # plt.subplot(122),plt.imshow(dst),plt.title('Output') # plt.show() cv2.imwrite(imgDir+'\\warpPerspective\\'+targetImg,dst) onlyImages = utils.getListOfImages(cfg.imgDir, cfg.imgFormats) imgRef = cv2.imread(cfg.imgDir+onlyImages[0],0) sift = cv2.SIFT() referenceKp, referenceDes = sift.detectAndCompute(imgRef,None) cv2.imwrite(cfg.imgDir+'warpPerspective\\'+onlyImages[0],imgRef) for i in range(1,len(onlyImages)): warpPerspective(referenceKp, referenceDes, cfg.imgDir, onlyImages[i]) #img=cv2.drawKeypoints(img1,kp1,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
def copyImages(baseDir, formats, targetDir): print 'Copying images from ', baseDir, ' to ', targetDir img_names = utils.getListOfImages(baseDir, formats) for img in img_names: copyfile(baseDir + img, targetDir + img) print '##############################################################'