예제 #1
0
def save_compressed_img(k, closest_points, centroids, rows, cols, colors, img, output=None, iteration=''):
    img_arr = np.zeros((rows*cols, colors))
    for i in range(k):
        img_arr[np.where(closest_points == i),:] = centroids[i]
    
    compressed_img = np.reshape(img_arr, (rows, cols, colors))
    if not output:
        img_ls = img.split('.')
        misc.imsave(str(k)+'k_compressed_' + ''.join(img_ls[:-1]) + iteration + '.' + img_ls[-1], compressed_img)
        return os.stat(str(k)+'k_compressed_' + ''.join(img_ls[:-1]) + iteration+ '.' + img_ls[-1]).st_size
    else:
        output_ls = output.split('.')
        misc.imsave(''.join(output_ls[:-1]) + iteration + '.' + output_ls[-1], compressed_img)
        return os.stat(''.join(output_ls[:-1]) + iteration + '.' + output_ls[-1]).st_size
예제 #2
0
def load_and_process(path,
                     locs,
                     ids,
                     prefix="_home_moffatopera_",
                     suffix='_binary.png',
                     plot=False):
    """asdfsadgsahfd"""

    if hasattr(locs, 'files'):
        iterable_locs = locs.files
    else:
        iterable_locs = locs

    #import progressbar as pbar
    #widg = widgets=[pbar.RotatingMarker(), ' ', pbar.Percentage(),' ', \
    #    pbar.Bar(), ' ', pbar.ETA()]
    #pb = pbar.ProgressBar(maxval=len(iterable_locs), widgets=widg).start()
    #count = 0

    allobjects = []
    allids = []
    for image in iterable_locs:
        print type(ids)
        imroot = image.split('.')[0]
        im = imread_binary(os.path.join(path, prefix + imroot + suffix))
        im_locs = locs[image]
        im_ids = ids[image]
        print prefix + imroot + suffix
        if plot:
            aligned_objects_from_im(im, im_locs, im_ids, image, plot=plot)
            print "Hit enter for next image."
        else:
            objects, newids = aligned_objects_from_im(im,
                                                      im_locs,
                                                      im_ids,
                                                      image,
                                                      plot=plot)
        #count += 1
        if not plot:
            allobjects.append(objects)
            allids.append(newids)
        #pb.update(count)
    if not plot:
        allobjects = np.concatenate(allobjects, axis=0)
        allids = np.concatenate(allids, axis=0)
        return allobjects, allids
예제 #3
0
def load_and_process(path, locs, ids, prefix="_home_moffatopera_",
    suffix='_binary.png',  plot=False):
    """asdfsadgsahfd"""
    
    if hasattr(locs,'files'):
        iterable_locs = locs.files
    else:
        iterable_locs = locs
    
    
    #import progressbar as pbar
    #widg = widgets=[pbar.RotatingMarker(), ' ', pbar.Percentage(),' ', \
    #    pbar.Bar(), ' ', pbar.ETA()]
    #pb = pbar.ProgressBar(maxval=len(iterable_locs), widgets=widg).start()
    #count = 0
    
    allobjects = []
    allids = []
    for image in iterable_locs:
        print type(ids)
        imroot = image.split('.')[0]
        im = imread_binary(os.path.join(path,prefix+imroot+suffix))
        im_locs = locs[image]
        im_ids = ids[image]
        print prefix+imroot+suffix
        if plot:
            aligned_objects_from_im(im,im_locs,im_ids,image,plot=plot)
            print "Hit enter for next image."
        else:
            objects, newids = aligned_objects_from_im(im,im_locs,im_ids,image,
                plot=plot)
        #count += 1
        if not plot:
            allobjects.append(objects)
            allids.append(newids)
        #pb.update(count)
    if not plot:
        allobjects = np.concatenate(allobjects,axis=0)
        allids = np.concatenate(allids,axis=0)
        return allobjects, allids
예제 #4
0
파일: loader.py 프로젝트: rashley2712/tools
	ppgplot.pgsci(1)
	ppgplot.pgenv(0, width-1, 0, height-1, 0, 0)
	
	outputWindow = ppgplot.pgopen('/xs')	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgsci(1)
	ppgplot.pgenv(0, width-1, 0, height-1, 0, 0)
	
	redReference = numpy.array(images[0].split()[0])
	redTotal = numpy.zeros(numpy.shape(redReference))
	greenTotal = numpy.zeros(numpy.shape(redReference))
	blueTotal = numpy.zeros(numpy.shape(redReference))
	
	for frameIndex, image in enumerate(images):
		redData, greenData, blueData = image.split()
		# redData.show()
		# print redData
		
		redData = numpy.array(redData)
		
		ppgplot.pgslct(previewWindow)
		ppgplot.pggray(redData, 0, width-1, 0, height-1, 0, 255, pgPlotTransform)
		
		# correlation = scipy.signal.correlate2d(redData, redReference, mode='same', boundary='symm')
		shift = phase_cor(redData, redReference)
		y, x = numpy.unravel_index(numpy.argmax(shift), shift.shape)
		if x > width/2:
			xd = width - x
		else: 
			xd = -x
예제 #5
0
			
	(width, height) = image.size
	
	previewWindow = ppgplot.pgopen('/xs')	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgsci(1)
	ppgplot.pgenv(0, width-1, 0, height-1, 0, 0)
	
	outputWindow = ppgplot.pgopen('/xs')	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgsci(1)
	ppgplot.pgenv(0, width-1, 0, height-1, 0, 0)
	
	redReference, greenReference, blueReference = image.split()
	redTotal = numpy.zeros(numpy.shape(redReference))
	greenTotal = numpy.zeros(numpy.shape(redReference))
	blueTotal = numpy.zeros(numpy.shape(redReference))
	redTotal+= numpy.array(redReference)
	greenTotal+= numpy.array(greenReference)
	blueTotal+= numpy.array(blueReference)
	for frameIndex in range(1, numImages):
		f = filesToLoad[frameIndex]
		image = Image.open(f)
		exposureTime = getExifValue(image, 'ExposureTime')
		print frameIndex,"/", numImages-1, " ", f, image.bits, image.size, image.format, image.mode, "Exposure time:", exposureTime
		
		redData, greenData, blueData = image.split()
		
		redData = numpy.array(redData)