Пример #1
0
    def get_filtered_image(self):
        fft_canvas = self.fft_panel.image_canvas
        canvas_rect = fft_canvas.get_shape_canvas_coords(fft_canvas.variables.select_rect_id)
        full_image_rect = fft_canvas.variables.canvas_image_object.canvas_rect_to_full_image_rect(canvas_rect)

        y_ul = int(full_image_rect[0])
        x_ul = int(full_image_rect[1])
        y_lr = int(full_image_rect[2])
        x_lr = int(full_image_rect[3])

        ft_cdata = self.get_all_fft_complex_data()
        filtered_cdata = np.zeros(ft_cdata.shape, ft_cdata.dtype)
        filtered_cdata[y_ul:y_lr, x_ul:x_lr] = ft_cdata[y_ul:y_lr, x_ul:x_lr]
        filtered_cdata = fftshift(filtered_cdata)

        inverse_flag = False
        ro = self.zoomer_panel.image_canvas.variables.canvas_image_object.reader_object
        if ro.sicd_meta.Grid.Col.Sgn > 0 and ro.sicd_meta.Grid.Row.Sgn > 0:
            pass
        else:
            inverse_flag = True

        if inverse_flag:
            cdata_clip = fft2(filtered_cdata)
        else:
            cdata_clip = ifft2(filtered_cdata)

        filtered_image = remap.density(cdata_clip)
        return filtered_image
Пример #2
0
    def run(self):
        cl = self.cl  # type: AlgorithmChain.ChainLedger
        params = self.params  # type: dict
        # Add your algorithm code here

        ro = params['sarpy_reader']
        decimation = params['decimation']
        remap_type = params['remap_type']

        cdata = ro.read_chip[::decimation, ::decimation]

        if remap_type == 'density':
            pix = remap.density(cdata)
        elif remap_type == 'brighter':
            pix = remap.brighter(cdata)
        elif remap_type == 'darker':
            pix = remap.darker(cdata)
        elif remap_type == 'highcontrast':
            pix = remap.highcontrast(cdata)
        elif remap_type == 'linear':
            pix = remap.linear(cdata)
        elif remap_type == 'log':
            pix = remap.log(cdata)
        elif remap_type == 'pedf':
            pix = remap.pedf(cdata)
        elif remap_type == 'nrl':
            pix = remap.nrl(cdata)

        cl.add_to_metadata('remapped_data', pix)
        cl.add_to_metadata('decimation', decimation)

        # Do not edit below this line
        return cl
Пример #3
0
    def get_filtered_image(self):
        select_rect_id = self.frequency_vs_degree_panel.canvas.variables.select_rect_id
        full_image_rect = self.frequency_vs_degree_panel.canvas.get_shape_image_coords(select_rect_id)

        y1 = int(full_image_rect[0])
        x1 = int(full_image_rect[1])
        y2 = int(full_image_rect[2])
        x2 = int(full_image_rect[3])

        y_ul = min(y1, y2)
        y_lr = max(y1, y2)
        x_ul = min(x1, x2)
        x_lr = max(x1, x2)

        ft_cdata = self.app_variables.fft_complex_data
        filtered_cdata = numpy.zeros(ft_cdata.shape, ft_cdata.dtype)
        filtered_cdata[y_ul:y_lr, x_ul:x_lr] = ft_cdata[y_ul:y_lr, x_ul:x_lr]
        filtered_cdata = fftshift(filtered_cdata)

        inverse_flag = False
        ro = self.app_variables.sicd_reader_object.base_reader
        if ro.sicd_meta.Grid.Col.Sgn > 0 and ro.sicd_meta.Grid.Row.Sgn > 0:
            pass
        else:
            inverse_flag = True

        if inverse_flag:
            cdata_clip = fft2(filtered_cdata)
        else:
            cdata_clip = ifft2(filtered_cdata)

        filtered_image = remap.density(cdata_clip)
        return filtered_image
Пример #4
0
    def run(self):
        cl = self.cl  # type: AlgorithmChain.ChainLedger
        params = self.params  # type: dict
        # Add your algorithm code here

        ro = params['sarpy_reader']
        decimation = params['decimation']

        if 'ystart' in params:
            ystart = params['ystart']
        else:
            ystart = 0

        if 'yend' in params:
            yend = params['yend']
        else:
            yend = ro.sicdmeta.ImageData.NumRows

        if 'xstart' in params:
            xstart = params['xstart']
        else:
            xstart = 0

        if 'xend' in params:
            xend = params['xend']
        else:
            xend = ro.sicdmeta.ImageData.NumCols

        remap_type = params['remap_type']

        cdata = ro.read_chip[ystart:yend:decimation, xstart:xend:decimation]

        if remap_type == 'density':
            pix = remap.density(cdata)
        elif remap_type == 'brighter':
            pix = remap.brighter(cdata)
        elif remap_type == 'darker':
            pix = remap.darker(cdata)
        elif remap_type == 'highcontrast':
            pix = remap.highcontrast(cdata)
        elif remap_type == 'linear':
            pix = remap.linear(cdata)
        elif remap_type == 'log':
            pix = remap.log(cdata)
        elif remap_type == 'pedf':
            pix = remap.pedf(cdata)
        elif remap_type == 'nrl':
            pix = remap.nrl(cdata)

        cl.add_to_metadata('remapped_data', pix)
        cl.add_to_metadata('decimation', decimation)

        # Do not edit below this line
        return cl
Пример #5
0
    def load_image(self, image_index):
        img_filename = self.image_names[image_index]

        if os.path.splitext(img_filename)[-1] == 'nitf':
            cdata = cf.open(img_filename).read_chip()
            img = remap.density(cdata)
        else:
            img = skimage.io.imread(img_filename)

        if len(img.shape) == 2:
            img = img[..., np.newaxis]

        return img.astype(np.float32)/255.0
Пример #6
0
    def callback_select_file(self, event):
        sicd_fname = self.image_info_panel.file_selector.event_select_file(event)
        self.app_variables.sicd_fname = sicd_fname
        self.app_variables.sicd_reader_object = sarpy_complex.open(sicd_fname)

        meticon_helper = SicdMetaIconHelper(self.app_variables.sicd_reader_object.sicd_meta)
        data_container = meticon_helper.data_container

        self.metaicon.create_from_metaicon_data_container(data_container)

        popup = tkinter.Toplevel(self.master)
        selected_region_popup = SelectedRegionPanel(popup, self.app_variables)
        self.app_variables.sicd_reader_object = ComplexImageReader(self.app_variables.sicd_fname)
        selected_region_popup.image_canvas.canvas.set_image_reader(self.app_variables.sicd_reader_object)

        self.master.wait_window(popup)

        selected_region_complex_data = self.app_variables.selected_region_complex_data

        fft_complex_data = self.get_fft_complex_data(self.app_variables.sicd_reader_object.base_reader, selected_region_complex_data)
        self.app_variables.fft_complex_data = fft_complex_data

        self.app_variables.fft_display_data = remap.density(fft_complex_data)
        fft_reader = NumpyImageReader(self.app_variables.fft_display_data)
        self.frequency_vs_degree_panel.canvas.set_image_reader(fft_reader)

        self.frequency_vs_degree_panel.canvas.set_current_tool_to_edit_shape()
        self.frequency_vs_degree_panel.canvas.variables.current_shape_id = self.frequency_vs_degree_panel.canvas.variables.select_rect_id
        self.frequency_vs_degree_panel.canvas.modify_existing_shape_using_image_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id, self.get_fft_image_bounds())
        canvas_drawing_bounds = self.frequency_vs_degree_panel.canvas.image_coords_to_canvas_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id)
        self.frequency_vs_degree_panel.canvas.variables.shape_drag_xy_limits[str(self.frequency_vs_degree_panel.canvas.variables.select_rect_id)] = canvas_drawing_bounds
        self.app_variables.fft_canvas_bounds = self.frequency_vs_degree_panel.canvas.get_shape_canvas_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id)
        self.frequency_vs_degree_panel.canvas.show_shape(self.frequency_vs_degree_panel.canvas.variables.select_rect_id)

        filtered_numpy_reader = NumpyImageReader(self.get_filtered_image())
        self.filtered_panel.canvas.set_image_reader(filtered_numpy_reader)

        self.image_info_panel.chip_size_panel.nx.set_text(numpy.shape(selected_region_complex_data)[1])
        self.image_info_panel.chip_size_panel.ny.set_text(numpy.shape(selected_region_complex_data)[0])

        self.update_phase_history_selection()

        self.metaviewer.create_w_sicd(self.app_variables.sicd_reader_object.base_reader.sicd_meta)

        self.frequency_vs_degree_panel.update()
        self.frequency_vs_degree_panel.update_x_axis(start_val=-10, stop_val=10, label="Polar Angle (degrees)")
        self.frequency_vs_degree_panel.update_y_axis(start_val=7.409, stop_val=11.39, label="Frequency (GHz)")
Пример #7
0
 def remap_complex_data(
         self,
         complex_data,  # type: np.ndarray
 ):
     if self.remap_type == 'density':
         pix = remap.density(complex_data)
     elif self.remap_type == 'brighter':
         pix = remap.brighter(complex_data)
     elif self.remap_type == 'darker':
         pix = remap.darker(complex_data)
     elif self.remap_type == 'highcontrast':
         pix = remap.highcontrast(complex_data)
     elif self.remap_type == 'linear':
         pix = remap.linear(complex_data)
     elif self.remap_type == 'log':
         pix = remap.log(complex_data)
     elif self.remap_type == 'pedf':
         pix = remap.pedf(complex_data)
     elif self.remap_type == 'nrl':
         pix = remap.nrl(complex_data)
     return pix
Пример #8
0
all_data = reader[:]  # or reader[:, :] - reads all data
decimated_data = reader[::10, ::10]  # reads every 10th pixel

# in the event of multiple image segments - use another slice index (defaults to 0)
# the image segment index defaults to 0 for multi-segment images

all_data = reader[:, :, 0]  # reads all data from the image segment at index 0
# = reader[:, :], reader[:] - yields same result, since image index defaults to 0

#################
# Show some basic plots of the data
from matplotlib import pyplot
import sarpy.visualization.remap as remap

fig, axs = pyplot.subplots(nrows=1, ncols=3, figsize=(12, 4))
axs[0].imshow(remap.density(reader[::10, ::10]), cmap='gray')
# Reads every other row and column from the first thousand rows and columns:
axs[1].imshow(remap.density(reader[:1000:2, :1000:2]),
              cmap='gray')  # Display subsampled image
# Reads every row and column from the first thousand rows and columns:
axs[2].imshow(remap.density(reader[0:1000, 0:1000]),
              cmap='gray')  # Display subsampled image
pyplot.show()

##############
# Convert a complex dataset (in any format handled by SarPy) to SICD

from sarpy.io.complex.converter import conversion_utility
# to SICD format
conversion_utility('<complex format file>', '<output_directory>')
# to SIO format
Пример #9
0
 def get_all_fft_display_data(self):
     ft_cdata = self.get_all_fft_complex_data()
     fft_display_data = remap.density(ft_cdata)
     return fft_display_data
Пример #10
0
    def update_displayed_selection(self):
        def get_extent(coords):
            return min(coords[0::2]), max(coords[0::2]), min(coords[1::2]), max(coords[1::2])

        def draw_row_delta_lines():
            deltak1 = (row_count - 1)*(0.5 + the_sicd.Grid.Row.SS*the_sicd.Grid.Row.DeltaK1) + 1
            deltak2 = (row_count - 1)*(0.5 + the_sicd.Grid.Row.SS*the_sicd.Grid.Row.DeltaK2) + 1

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_deltak1, (deltak1, 0, deltak1, col_count))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_deltak2, (deltak2, 0, deltak2, col_count))

        def draw_col_delta_lines():
            deltak1 = (col_count - 1)*(0.5 + the_sicd.Grid.Col.SS*the_sicd.Grid.Col.DeltaK1) + 1
            deltak2 = (col_count - 1)*(0.5 + the_sicd.Grid.Col.SS*the_sicd.Grid.Col.DeltaK2) + 1

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_deltak1, (0, deltak1, row_count, deltak1))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_deltak2, (0, deltak2, row_count, deltak2))

        def draw_row_bandwidth_lines():
            try:
                delta_kcoa_center = the_sicd.Grid.Row.DeltaKCOAPoly(row_phys, col_phys)
            except Exception:
                delta_kcoa_center = 0.0

            row_bw_low = (row_count - 1)*(
                    0.5 + the_sicd.Grid.Row.SS*(delta_kcoa_center - 0.5*the_sicd.Grid.Row.ImpRespBW)) + 1
            row_bw_high = (row_count - 1)*(
                    0.5 + the_sicd.Grid.Row.SS*(delta_kcoa_center + 0.5*the_sicd.Grid.Row.ImpRespBW)) + 1

            row_bw_low = (row_bw_low % row_count)
            row_bw_high = (row_bw_high % row_count)

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_line_low, (row_bw_low, 0, row_bw_low, col_count))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_line_high, (row_bw_high, 0, row_bw_high, col_count))

        def draw_col_bandwidth_lines():
            try:
                delta_kcoa_center = the_sicd.Grid.Col.DeltaKCOAPoly(row_phys, col_phys)
            except Exception:
                delta_kcoa_center = 0.0

            col_bw_low = (col_count - 1) * (
                    0.5 + the_sicd.Grid.Col.SS*(delta_kcoa_center - 0.5*the_sicd.Grid.Col.ImpRespBW)) + 1
            col_bw_high = (col_count - 1) * (
                    0.5 + the_sicd.Grid.Col.SS*(delta_kcoa_center + 0.5*the_sicd.Grid.Col.ImpRespBW)) + 1

            col_bw_low = (col_bw_low % col_count)
            col_bw_high = (col_bw_high % col_count)

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_line_low, (0, col_bw_low, row_count, col_bw_low))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_line_high, (0, col_bw_high, row_count, col_bw_high))

        threshold = self.image_panel.canvas.variables.config.select_size_threshold
        select_id = self.image_panel.canvas.variables.select_rect.uid
        rect_coords = self.image_panel.canvas.get_shape_image_coords(select_id)
        extent = get_extent(rect_coords)  # left, right, bottom, top
        row_count = extent[1] - extent[0]
        col_count = extent[3] - extent[2]

        the_sicd = self.variables.image_reader.get_sicd()
        row_phys, col_phys = get_physical_coordinates(
            the_sicd, 0.5*(extent[0]+extent[1]), 0.5*(extent[2]+extent[3]))

        if row_count < threshold or col_count < threshold:
            junk_data = numpy.zeros((100, 100), dtype='uint8')
            self.frequency_panel.set_image_reader(NumpyImageReader(junk_data))
            self._initialize_bandwidth_lines()
        else:
            image_data = self.variables.image_reader.base_reader[extent[0]:extent[1], extent[2]:extent[3]]
            if image_data is not None:
                self.frequency_panel.set_image_reader(
                    NumpyImageReader(remap.density(fftshift(fft2_sicd(image_data, the_sicd)))))
                self._initialize_bandwidth_lines()
                draw_row_delta_lines()
                draw_col_delta_lines()
                draw_row_bandwidth_lines()
                draw_col_bandwidth_lines()
            else:
                junk_data = numpy.zeros((100, 100), dtype='uint8')
                self.frequency_panel.set_image_reader(NumpyImageReader(junk_data))
                self._initialize_bandwidth_lines()
Пример #11
0
# Access SICD metadata (even if file read is not in SICD format)
print(ro.sicd_meta
      )  # Displays metadata from file in SICD format in human-readable form
print(ro.sicd_meta.CollectionInfo.CollectorName
      )  # extracting fields from metadata

###############
# Read complex pixel data from file
# cdata = ro[:]  # Reads all complex data from file

# Read every 10th pixel:
cdata = ro[::10, ::10]

fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(12, 4))
axs[0].imshow(remap.density(cdata), cmap='gray')  # Display subsampled image

# Reads every other row and column from the first thousand rows and columns:
cdata = ro[:1000:2, :1000:2]
axs[1].imshow(remap.density(cdata), cmap='gray')  # Display subsampled image

# Reads every row and column from the first thousand rows and columns:
cdata = ro[0:1000, 0:1000]
axs[2].imshow(remap.density(cdata), cmap='gray')  # Display subsampled image
plt.show()

##############
# Convert a complex dataset (in any format handled by SarPy) to SICD
cf.convert(fname, 'C:/Temp/new_sicd.nitf')
# Convert a complex data to SIO
output_directory = 'C:/Temp'
Пример #12
0
cdata = cdata[0:1000, 0:1000]

inverseFlag = False
if ro.sicd_meta.Grid.Col.Sgn > 0 and ro.sicd_meta.Grid.Row.Sgn > 0:
    # use fft2 to go from image to spatial freq
    ft_cdata = fft2(cdata)
else:
    # flip using ifft2
    ft_cdata = ifft2(cdata)
    inverseFlag = True

ft_cdata = fftshift(ft_cdata)

print("display fft'd data")
plt.figure()
plt.imshow(remap.density(ft_cdata), cmap='gray')
plt.show()

print("clip fft data and display reconstruction")
# TODO replace with padded windowing function and multiply
filtered_cdata = np.zeros(ft_cdata.shape, ft_cdata.dtype)
filtered_cdata[1500:2000, 3000:4000] = ft_cdata[1500:2000, 3000:4000]
filtered_cdata = fftshift(filtered_cdata)

if inverseFlag:
    cdata_clip = fft2(filtered_cdata)
else:
    cdata_clip = ifft2(filtered_cdata)

plt.figure()
plt.imshow(remap.density(cdata_clip), cmap='gray')
Пример #13
0
# Open file
fname = 'C:/Temp/my_sicd.nitf'
ro = cf.open(fname)

# Access SICD metadata (even if file read is not in SICD format)
print(ro.sicdmeta
      )  # Displays metadata from file in SICD format in human-readable form
ro.sicdmeta  # Displays XML representation of SICD metadata
print(ro.sicdmeta.CollectionInfo.CollectorName
      )  # Notation for extracting fields from metadata

# Read complex pixel data from file
# cdata = reader_object.read_chip[...] # Reads all complex data from file
# Read every 10th pixel:
cdata = ro.read_chip[::10, ::10]
plt.figure()
plt.imshow(remap.density(cdata), cmap='gray')  # Display subsampled image
# Reads every other row and column from the first thousand rows and columns:
cdata = ro.read_chip[:1000:2, :1000:2]
plt.figure()
plt.imshow(remap.density(cdata), cmap='gray')  # Display subsampled image
# Reads every row and column from the first thousand rows and columns:
cdata = ro.read_chip[0:1000, 0:1000]
plt.figure()
plt.imshow(remap.density(cdata), cmap='gray')  # Display subsampled image

# Convert a complex dataset (in any format handled by SarPy) to SICD
cf.convert(fname, 'C:/Temp/new_sicd.nitf')
# Convert a complex data to SIO
cf.convert(fname, 'C:/Temp/new_sio.sio', output_format='sio')
Пример #14
0
    buffering=4*1024*1024)  # it has been observed that setting a manual buffer size may help



"""
Basic data plot
---------------

Show some basic plots of the data.
 
**Note:** the sarpy_apps project provides robust interactive tools.
"""

from matplotlib import pyplot
import sarpy.visualization.remap as remap

fig, axs = pyplot.subplots(nrows=1, ncols=1, figsize=(5, 5))
axs.imshow(remap.density(all_data), cmap='gray')
pyplot.show()


"""
Convert to SICD format
----------------------

Convert a complex dataset, in any format handled by sarpy, to SICD
"""

from sarpy.io.complex.converter import conversion_utility
conversion_utility('<complex format file>', '<output_directory>')