def setUp(self): blank = np.zeros((24,24),np.uint16) peak = blank.copy() peak[ 12:14, 15:17 ] = 42 # put a peak on every other image for i in range(self.FIRST, self.LAST+1): if i%2 == 0: obj = tifimage.tifimage( peak, { } ) self.NPK += 1 print( i, self.NPK) else: obj = tifimage.tifimage( blank, { } ) obj.write( 'tiftest%04d.tif'%(i))
def writeimage(image, path, mask=None, headers=None, suffix='',ext=None, dialog=False): if dialog: filename,ok = dialogs.savedatadialog(guesspath=path,caption="Save data to "+ext) if filename and ok: writeimage(image, filename, headers) if mask is not None: maskname = ''.join(os.path.splitext(filename)[:-1]) + "_mask" + os.path.splitext(filename)[-1] writeimage(mask, maskname, headers) if headers is None: headers = dict() if ext is None: ext = os.path.splitext(path)[-1] path = ''.join(os.path.splitext(path)[:-1]) + suffix + ext if notexitsoroverwrite(path): if ext.lower() == '.edf': fabimg = edfimage.edfimage(np.rot90(image), header=headers) fabimg.write(path) elif ext.lower() == '.tif': fabimg = tifimage.tifimage(np.rot90((image.astype(float)/image.max()*2**16).astype(np.int16)), header=headers) fabimg.write(path) elif ext.lower() == '.png': raise NotImplementedError elif ext.lower() == '.jpg': scipy.misc.imsave(path,np.rot90(image)) else: return False return True
def setUp(self): """ create an image """ self.imdata = numpy.zeros((24, 24), numpy.uint16) self.imdata[12:14, 15:17] = 42 obj = tifimage(self.imdata, {}) obj.write(self.image)
def setUp(self): """ create an image """ self.imdata = numpy.zeros((24, 24), numpy.uint16) self.imdata[ 12:14, 15:17 ] = 42 obj = tifimage(self.imdata, { }) obj.write(self.image)
def setUp(self): """ create an image """ self.image = os.path.join(UtilsTest.tempdir, "tifimagewrite_test0000.tif") self.imdata = numpy.zeros((24, 24), numpy.uint16) self.imdata[12:14, 15:17] = 42 obj = tifimage(self.imdata, {}) obj.write(self.image)
def writeimage(image, path, headers=None, suffix='', ext=None): if headers is None: headers = dict() if ext is None: ext = os.path.splitext(path)[-1] path = ''.join(os.path.splitext(path)[:-1]) + suffix + ext if notexitsoroverwrite(path): if ext.lower() == '.edf': fabimg = edfimage.edfimage(np.rot90(image), header=headers) fabimg.write(path) elif ext.lower() == '.tif': fabimg = tifimage.tifimage(np.rot90( (image.astype(float) / image.max() * 2**16).astype(np.int16)), header=headers) fabimg.write(path) elif ext.lower() == '.png': raise NotImplementedError elif ext.lower() == '.jpg': scipy.misc.imsave(path, np.rot90(image)) else: return False return True
def write_tif(self, framenumber, frame): e = tifimage.tifimage() e.data = frame e.write('%s%s' % (self.graindata.frameinfo[framenumber].name, '.tif'))
def center(self, sample=True): """ Slot to receive signal when user requests a centered image. Performs centering and writes new image into current working directory Parameters ---------- sample: boolean, optional flag whether image to be centered is the original sample or the mask image """ if sample: if self.edited_image is not None: msg.showMessage('Image already centered.') return image = self.orig_image else: image = self.mask #resize image so that it's in center and displays output if a sample image xdim = int(image.shape[0]) ydim = int(image.shape[1]) newx = xdim + 2*abs(self.cameraLocation[0]-xdim/2) newy = ydim + 2*abs(self.cameraLocation[1]-ydim/2) self.new_dim = max(newx,newy) self.edited_image = np.ones((self.new_dim,self.new_dim),dtype = np.int) new_center = (self.new_dim/2,self.new_dim/2) lowleft_corner_x = int(new_center[0]-self.cameraLocation[0]) lowleft_corner_y = int(new_center[1]-self.cameraLocation[1]) self.edited_image[lowleft_corner_x:lowleft_corner_x+xdim,lowleft_corner_y: lowleft_corner_y+ydim] = image # save image if sample: self.write_path = self.path if self.write_path.endswith('.tif'): self.write_path = self.write_path[:-4] + '_centered.tif' else: self.write_path += '_centered.tif' self.write_path_sample = self.write_path img = tifimage.tifimage(np.rot90((self.edited_image.astype(float) / self.edited_image.max() * 2 ** 16).astype(np.int16))) else: self.write_path = self.mask_path if self.write_path.endswith('.tif'): self.write_path = self.write_path[:-4] + '_centered.tif' else: self.write_path += '_centered.tif' self.write_path_mask = self.write_path img = tifimage.tifimage(np.rot90(self.edited_image.astype(float))) img.write(self.write_path) if sample: self.edited_view.setImage(self.edited_image) box = self.drawCameraLocation(self.edited_view,new_center) self.drawROI(lowleft_corner_x,lowleft_corner_y,xdim,ydim,'r', box) self.drawROI(0,0,self.new_dim,self.new_dim, 'b', box) # this is a temporary fix for a problem: pushing a button changes tab back to first self.image_holder.setCurrentIndex(1)