コード例 #1
0
ファイル: Pixmap.py プロジェクト: mohseniaref/PyRAT
    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
コード例 #2
0
    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
コード例 #3
0
ファイル: Pixmap.py プロジェクト: birgander2/PyRAT
    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
コード例 #4
0
ファイル: Pixmap.py プロジェクト: zhanghai4155/PyRAT
    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
コード例 #5
0
ファイル: Pixmap.py プロジェクト: IvanLJF/PyRAT
    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