def writer(self, array, *args, **kwargs): if self.scale == 'SAR' and np.iscomplexobj(array): array = np.abs(array) array = np.squeeze(array) out = np.zeros_like(array, dtype='uint8') if array.ndim == 3 and self.chscl == True: for k in range(array.shape[0]): array[k, ...] = array[k, ...] / np.mean(array[k, ...]) if self.scale == 'SAR': out = sarscale(array) elif self.scale == 'phase': out = phascale(array) elif self.scale == 'coherence': out = cohscale(array) else: logging.error("Scaling method unknown") return False if array.ndim == 3: out = out[self.order, ...] try: misc.imsave(self.filename, out, format=self.key) return True except IOError as err: logging.error("ERROR:"+str(err)) return False else: logging.error("UNKNOWN ERROR") return False
def writer(self, array, *args, **kwargs): if isinstance(self.file, tuple): # remove file type if present self.file = self.file[0] if (self.method == 'amplitude' or self.method == 'intensity') and np.iscomplexobj(array): array = np.abs(array) array = np.squeeze(array) if array.ndim == 4: nchannels = np.prod(array.shape[0:array.ndim - 2]) array = np.reshape(array, (nchannels, ) + array.shape[array.ndim - 2:]) if array.ndim == 3 and self.chscl == True: for k in range(array.shape[0]): array[k, ...] = array[k, ...] / np.mean(array[k, ...]) if self.method == 'intensity' or self.method == 'amplitude': if self.method == 'amplitude': array **= 0.7 if self.method == 'intensity': array **= 0.35 out = sarscale(array, factor=self.scaling) elif self.method == 'phase': out = phascale(array) elif self.method == 'coherence': out = cohscale(array) elif self.method == 'minmax': start = array.min() end = array.max() out = np.uint8( np.clip((array - start) / (end - start) * 255, 0, 255)) else: logging.error("Scaling method unknown") return False if array.ndim == 3: if out.shape[0] < 3: oshp = out.shape oshp[0] = 3 out = np.resize(out, oshp) if out.shape[0] > 3: out = out[0:3, ...] out = np.rollaxis(np.rollaxis(out[self.order, ...], 2), 2) else: out = colortables(self.palette)[1][out] try: pilimg = Image.fromarray(out) pilimg.save(self.file, format=self.key) logging.info("FINISHED SAVING IMAGE") return True except IOError as err: logging.error("ERROR:" + str(err)) return False else: logging.error("UNKNOWN ERROR") return False
def filter(self, array, *args, **kwargs): shp = array.shape array = array.reshape((np.prod(shp[0:-2]),) + shp[-2:]) # reshape to (nch, ny, nx) selem = np.ones(self.win) for k, amp in enumerate(np.abs(array)): # loop over channels array[k, ...] = skentropy(sarscale(amp), selem) array = array.reshape(shp) # back to original shape return array
def filter(self, array, *args, **kwargs): shp = array.shape array = array.reshape( (np.prod(shp[0:-2]), ) + shp[-2:]) # reshape to (nch, ny, nx) selem = np.ones(self.win) for k, amp in enumerate(np.abs(array)): # loop over channels array[k, ...] = skentropy(sarscale(amp), selem) array = array.reshape(shp) # back to original shape return array
def data2img(self, cut_box, scale=0): if self.config['colour'] is False: channel = [int(self.config['bwlayer'].split('D')[1])] else: channel = [ int(foo.split('D')[1]) for foo in self.config['rgblayer'] ] method = self.config['scaling'] img = self.data[scale][..., cut_box[2]:cut_box[3], cut_box[0]:cut_box[1]][channel, ...].copy() if img.dtype == 'uint8': img = img.copy() elif method == 'amplitude' or method == 'intensity' or method == None: if method == 'intensity': img = np.abs(img)**0.35 else: img = np.abs(img)**0.7 if self.config['colour'] is True: for k in range(img.shape[0]): img[k, ...] /= np.mean(img[k, ...]) img = sarscale(img, factor=self.sarscale) elif method == 'phase': img = np.uint8(np.clip(img / np.pi * 128 + 127, 0.0, 255.0)) elif method == '0.0->1.0': img = np.uint8(np.clip(img * 255.0, 0.0, 255.0)) elif method == 'min->max': img -= np.min(img) img = np.uint8(img / np.max(img) * 255.0) elif method == 'labels': img -= np.min(self.data[0]) img = np.uint8(img / np.max(self.data[0]) * 255.0) else: img = np.uint8(int) # img = img[..., 0:img.shape[-2] // 4 * 4, 0:img.shape[-1] // 4 * 4] # QT Limitation!! img = np.rollaxis(np.rollaxis(img, axis=2), axis=2) if self.config['palette'] != 0: self.img = colortables(self.config['palette'])[1][img] else: self.img = img # img = np.rot90(np.rollaxis(np.rollaxis(img, axis=2), axis=2)) if self.config['colour'] is True: return QtGui.QImage(img.tostring(), img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888) else: return QtGui.QImage(img.tostring(), img.shape[1], img.shape[0], QtGui.QImage.Format_Indexed8)
def writer(self, array, *args, **kwargs): if isinstance(self.file, tuple): # remove file type if present self.file = self.file[0] if (self.method == 'amplitude' or self.method == 'intensity') and np.iscomplexobj(array): array = np.abs(array) array = np.squeeze(array) if array.ndim == 4: nchannels = np.prod(array.shape[0:array.ndim-2]) array = np.reshape(array, (nchannels, )+array.shape[array.ndim-2:]) if array.ndim == 3 and self.chscl == True: for k in range(array.shape[0]): array[k, ...] = array[k, ...] / np.mean(array[k, ...]) if self.method == 'intensity' or self.method == 'amplitude': if self.method == 'amplitude': array **= 0.7 if self.method == 'intensity': array **= 0.35 out = sarscale(array, factor=self.scaling) elif self.method == 'phase': out = phascale(array) elif self.method == 'coherence': out = cohscale(array) elif self.method == 'minmax': start = array.min() end = array.max() out = np.uint8(np.clip((array - start) / (end - start) * 255, 0, 255)) else: logging.error("Scaling method unknown") return False if array.ndim == 3: out = np.rollaxis(np.rollaxis(out[self.order, ...], 2), 2) else: out = colortables(self.palette)[1][out] try: pilimg = Image.fromarray(out) pilimg.save(self.file, format=self.key) logging.info("FINISHED SAVING IMAGE") return True except IOError as err: logging.error("ERROR:" + str(err)) return False else: logging.error("UNKNOWN ERROR") return False
def writer(self, array, *args, **kwargs): if isinstance(self.file, tuple): # remove file type if present self.file = self.file[0] if (self.method == 'amplitude' or self.method == 'intensity') and np.iscomplexobj(array): array = np.abs(array) array = np.squeeze(array) if array.ndim == 4: nchannels = np.prod(array.shape[0:array.ndim - 2]) array = np.reshape(array, (nchannels, ) + array.shape[array.ndim - 2:]) if array.ndim == 3 and self.chscl == True: for k in range(array.shape[0]): array[k, ...] = array[k, ...] / np.mean(array[k, ...]) if self.method == 'intensity' or self.method == 'amplitude': if self.method == 'amplitude': array **= 0.7 if self.method == 'intensity': array **= 0.35 out = sarscale(array, factor=self.scaling) elif self.method == 'phase': out = phascale(array) elif self.method == 'coherence': out = cohscale(array) else: logging.error("Scaling method unknown") return False if array.ndim == 3: out = np.rollaxis(np.rollaxis(out[self.order, ...], 2), 2) else: out = colortables(self.palette)[1][out] try: misc.imsave(self.file, out, format=self.key) logging.info("FINISHED SAVING IMAGE") return True except IOError as err: logging.error("ERROR:" + str(err)) return False else: logging.error("UNKNOWN ERROR") return False
def writer(self, array, *args, **kwargs): if isinstance(self.file, tuple): # remove file type if present self.file = self.file[0] if self.method == 'amplitude' or self.method == 'intensity' and np.iscomplexobj( array): array = np.abs(array) array = np.squeeze(array) out = np.zeros_like(array, dtype='uint8') if array.ndim == 3 and self.chscl == True: for k in range(array.shape[0]): array[k, ...] = array[k, ...] / np.mean(array[k, ...]) if self.method == 'intensity' or self.method == 'amplitude': if self.method == 'amplitude': array **= 0.7 if self.method == 'intensity': array **= 0.35 out = sarscale(array, factor=self.scaling) elif self.method == 'phase': out = phascale(array) elif self.method == 'coherence': out = cohscale(array) else: logging.error("Scaling method unknown") return False if array.ndim == 3: out = out[self.order, ...] else: out = colortables(self.palette)[1][out] try: misc.imsave(self.file, out, format=self.key) return True except IOError as err: logging.error("ERROR:" + str(err)) return False else: logging.error("UNKNOWN ERROR") return False
def data2img(self, cut_box, scale=0): if self.config['colour'] is False: channel = [int(self.config['bwlayer'].split('D')[1])] else: channel = [int(foo.split('D')[1]) for foo in self.config['rgblayer']] method = self.config['scaling'] img = self.data[scale][..., cut_box[2]:cut_box[3], cut_box[0]:cut_box[1]][channel, ...].copy() if img.dtype == 'uint8': img = img.copy() elif method == 'amplitude' or method == 'intensity': if method == 'intensity': img **= 0.35 else: img **= 0.7 if self.config['colour'] is True: for k in range(img.shape[0]): img[k, ...] /= np.mean(img[k, ...]) img = sarscale(img, factor=self.sarscale) elif method == 'phase': img = np.uint8(np.clip(img / np.pi * 128 + 127, 0.0, 255.0)) elif method == '0.0->1.0': img = np.uint8(np.clip(img * 255.0, 0.0, 255.0)) elif method == 'min->max' or method == 'lables': img += np.min(img) img = np.uint8(img / np.max(img) * 255.0) else: img = np.uint8(int) # img = img[..., 0:img.shape[-2] // 4 * 4, 0:img.shape[-1] // 4 * 4] # QT Limitation!! img = np.rollaxis(np.rollaxis(img, axis=2), axis=2) # img = np.rot90(np.rollaxis(np.rollaxis(img, axis=2), axis=2)) if self.config['colour'] is True: return QtGui.QImage(img.tostring(), img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888) else: return QtGui.QImage(img.tostring(), img.shape[1], img.shape[0], QtGui.QImage.Format_Indexed8)
def pre(self, *args, **kwargs): amp = pyrat.data.getData() amp = np.uint8(np.float32(sarscale(amp)) / (256.0 / self.levels)) newlayer = pyrat.data.addLayer(amp) pyrat.data.activateLayer(newlayer)