예제 #1
0
def showdata(args):
    cvd.checkresize(args.resize_imageW, args.resize_imageH, 
                    args.resize_saliencyW, args.resize_saliencyH)
    cvd.checknormalizerange(args.normalize_image, 
                            args.normalize_saliency)
    filelist = cvd.getfilelist(args.imagefolder, args.saliencyfolder, 
                               args.listfile, args.shuffle)
    
    # get the shape for h5py dataset
    image, saliency = cvd.convertimageandmat(filelist[14], args.gray, 
                                             args.check_size, 
                                             args.resize_imageW, 
                                             args.resize_imageH,
                                             args.resize_saliencyW, 
                                             args.resize_saliencyH, 
                                             args.normalize_image, 
                                             args.normalize_saliency)
    
    with h5py.File('datasetmean.hdf5') as f:
        mset = f.get('mean')
        imagemean = mset[0]
    mean_c = imagemean.mean(1).mean(1)
    for i in range(imagemean.shape[0]):
        imagemean[i].fill(mean_c[i])
    image = image.astype(np.float32)
    image -= imagemean
    image = cvd.chw2hwc(image, args.gray)
    image = cvd.normalizeimage(image, args.normalize_image) 
    saliency = cvd.l2hw(saliency, args.resize_saliencyW, args.resize_saliencyH)
    plt.figure()
    skimage.io.imshow(image)
    plt.figure()
    skimage.io.imshow(saliency)
    skimage.io.show()
예제 #2
0
def createdata(args):
    logger_root = logging.getLogger()
    cvd.checkresize(args.resize_imageW, args.resize_imageH, 
                    args.resize_saliencyW, args.resize_saliencyH)
    cvd.checknormalizerange(args.normalize_image, 
                            args.normalize_saliency)
    filelist = cvd.getfilelist(args.imagefolder, args.saliencyfolder, 
                               args.listfile, args.shuffle)
    
    # get the shape for h5py dataset
    image, saliency = cvd.convertimageandmat(filelist[0], args.gray, 
                                             args.check_size, 
                                             args.resize_imageW, 
                                             args.resize_imageH,
                                             args.resize_saliencyW, 
                                             args.resize_saliencyH, 
                                             args.normalize_image, 
                                             args.normalize_saliency)
                                         
    N = len(filelist)
    datashape = tuple([N]) + image.shape
    labelshape = tuple([N]) + saliency.shape
    
    with h5py.File('datasetmean.hdf5') as f:
        mset = f.get('mean')
        imagemean = mset[0]
    mean_c = imagemean.mean(1).mean(1)
    for i in range(imagemean.shape[0]):
        imagemean[i].fill(mean_c[i])
        
    # write to h5py dataset
    with h5py.File(args.outfile) as f:
        dset = f.create_dataset(name = 'data', shape = datashape, 
                                dtype = np.dtype(np.float32), 
                                compression = "gzip", compression_opts = 4)
        lset = f.create_dataset(name = 'label', shape = labelshape, 
                                dtype = np.dtype(np.float32), 
                                compression = "gzip", compression_opts = 4)
        for i in range(N):
            image, saliency = cvd.convertimageandmat(filelist[i],
                                                     args.gray,
                                                     args.check_size, 
                                                     args.resize_imageW, 
                                                     args.resize_imageH, 
                                                     args.resize_saliencyW, 
                                                     args.resize_saliencyH, 
                                                     args.normalize_image, 
                                                     args.normalize_saliency)
            image = image.astype(np.float32)
            image -= imagemean
            image = cvd.chw2hwc(image, args.gray)
            image = cvd.normalizeimage(image, args.normalize_image)
            image = cvd.hwc2chw(image, args.gray)
            dset[i] = image
            lset[i] = saliency
            if((i + 1) % 100 == 0):
                logger_root.info('Processed %d files.' %(i + 1))
        if((i + 1) % 100 != 0):
            logger_root.info('Processed %d files.' %(i + 1))
예제 #3
0
def computerimagemean(args):
    logger_root = logging.getLogger()
    filelist = cvd.getfilelist(args.imagefolder, args.saliencyfolder, 
                               args.listfile, args.shuffle)
    imagelist = filelist[:,0]
    image = cvd.convertimage(imagelist[0], args.gray, args.resize_imageW, 
                             args.resize_imageH, args.normalize_image)
    N = len(imagelist)
    imagemean = np.zeros(image.shape, dtype = np.float64)
    for i in range(N):
        image = cvd.convertimage(imagelist[i], args.gray, 
                                         args.resize_imageW, 
                                         args.resize_imageH, 
                                         args.normalize_image)
        imagemean += image
        if((i + 1) % 100 == 0):
            logger_root.info('Processed %d files.' %(i + 1))
    if((i + 1) % 100 != 0):
        logger_root.info('Processed %d files.' %(i + 1))
    imagemean /= (N + 1)
    # range [0.0 255.0] means image is uint8
    if(args.normalize_image[0] == 0 and args.normalize_image[1] == 255):
        return imagemean.astype(np.uint8)
    return imagemean.astype(np.float32)
예제 #4
0
        sys.exit(1)
    if args.resize_imageH <= 0:
        logger_root = logging.getLogger()
        logger_root.error("resize_imageH should be greater than 0")
        sys.exit(1)

    if args.resize_saliencyW <= 0:
        logger_root = logging.getLogger()
        logger_root.error("resize_saliencyW should be greater than 0")
        sys.exit(1)
    if args.resize_saliencyH <= 0:
        logger_root = logging.getLogger()
        logger_root.error("resize_saliencyH should be greater than 0")
        sys.exit(1)

    filelist = convertdata.getfilelist(args.imagefolder, args.saliencyfolder, args.listfile, args.shuffle)

    imageHWC, saliency = convertdata.readimageandmat(
        filelist[8],
        args.gray,
        args.check_size,
        args.resize_imageW,
        args.resize_imageH,
        args.resize_saliencyW,
        args.resize_saliencyH,
    )
    imageCHW = imageHWC.transpose((2, 0, 1))
    saliency = saliency.flatten()

    input_arrays = np.zeros([1, 3, 96, 96], np.float32)
    input_arrays[0] = imageCHW