Ejemplo n.º 1
0
def visualcheckImageDB(imagedb,imagedbtype=0,zoom=0.5):
    import procdb
    if imagedbtype==0:
        images,shape,labels=procdb.processImageDB(imagedb)
    else:
        images,shape=procdb.processImageDB2(imagedb)

    shape=np.asarray(shape)
    print shape
    
    for i in range(len(images)):
        im=Image.open(images[i])
        im=drawPointsOnImage(im,shape[i,:,0],shape[i,:,1])
        im=im.resize((int(im.size[0]*zoom+0.5),int(im.size[1]*zoom+0.5)))
        print images[i]
        im.show()
        raw_input('Press ENTER to proceed to next image...')
    return
Ejemplo n.º 2
0
def cropnscaleImageDB(imagedb,newimagedb,ox,oy,width,height,scale,folder="",verbose=False):
    """
    Applies a crop (region of interest) followed by a scale operation
    on a set of images listed on an image database.

    The feature points on the image databased are modified to reflect
    the operations.
        
    Key arguments:
    imagedb   -- filename/path of the image database
    newimagedb  -- name of the file that will be created
    ox -- x origin of the crop operation
    oy -- y origin of the crop operation
    width -- width of the region of interest
    height -- height of the region of interest
    scale -- used to resize the region of interest
    folder -- where the images are going to be saved; if not provided,
              a new directory is created automatically.
    verbose -- If True provides feedback about the images being processed
    
    """


    import procdb
    import os

    images,shapes,labels=procdb.processImageDB(imagedb)
    shapes=np.asarray(shapes)
    #print shapes.shape

    if verbose==True:
        print str(len(images))+" images to process."
    
    
    suffix="_"+str(int(width*scale))+"x"+str(int(height*scale))
    if folder=="":
        folder=str(int(width*scale))+"x"+str(int(height*scale))
        if not os.path.exists(folder): os.makedirs(folder)
    else:
        if not os.path.exists(folder):os.makedirs(folder)

    newimagedb=open(folder+"/"+newimagedb,'w')

    for i in range(len(images)):
        im=cv2.imread(images[i])
        im_cropped=crop(im,ox,oy,width,height)
        newheight=int(height*scale)
        newwidth=int(width*scale)
        im_resized=np.asarray(np.zeros((newheight,newwidth)))
        im_resized=cv2.resize(im_cropped,(newwidth,newheight),im_resized,scale,scale,cv2.INTER_AREA)
        fileName, fileExtension = os.path.splitext(images[i])
        
        retval=cv2.imwrite(folder+"/"+fileName+suffix+fileExtension,im_resized)
        if retval==False:
            print "Problem to save modified image."
            return False
        shapes[i,:,0]=shapes[i,:,0]-ox
        shapes[i,:,1]=shapes[i,:,1]-oy
        shapes[i]=shapes[i]*scale

        newshapes=''
        for j in range(shapes.shape[1]):
            newshapes=newshapes+',('+str(shapes[i,j,0])+';'+str(shapes[i,j,1])+')'

        newlabels=''
        for k in range(len(labels[i])):
            newlabels=newlabels+','+str(labels[i][k])

        newimagedb.write(fileName+suffix+fileExtension+newlabels+newshapes+'\n')

        if verbose==True:
            print "Image "+str(i+1)+" successfully processed."
        
    newimagedb.close()

    return True