Exemple #1
0
    def __init__(self, image, parent=None):
        super(SplicingWidget, self).__init__(parent)

        self.image = image
        self.image0 = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY).astype(
            np.float32) / 255
        self.noise = self.map = None

        self.noise_button = QPushButton(self.tr('(1/2) Estimate noise'))
        modify_font(self.noise_button, bold=True)
        gray = np.full_like(self.image, 127)
        self.noise_viewer = ImageViewer(self.image,
                                        gray,
                                        self.tr('Estimated noise print'),
                                        export=True)
        self.map_button = QPushButton(self.tr('(2/2) Compute heatmap'))
        modify_font(self.map_button, bold=True)
        self.map_button.setEnabled(False)
        self.map_viewer = ImageViewer(self.image, gray,
                                      self.tr('Splicing probability heatmap'))

        self.noise_button.clicked.connect(self.estimate_noise)
        self.noise_button.toggled.connect(self.estimate_noise)
        self.map_button.clicked.connect(self.compute_map)
        self.map_button.toggled.connect(self.compute_map)

        main_layout = QGridLayout()
        main_layout.addWidget(self.noise_viewer, 0, 0)
        main_layout.addWidget(self.noise_button, 1, 0)
        main_layout.addWidget(self.map_viewer, 0, 1)
        main_layout.addWidget(self.map_button, 1, 1)
        self.setLayout(main_layout)
Exemple #2
0
    def __init__(self, image, parent=None):
        super(ElaWidget, self).__init__(parent)

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Quality:')))
        self.quality_spin = QSpinBox()
        self.quality_spin.setRange(0, 100)
        self.quality_spin.setSuffix(self.tr(' %'))
        self.quality_spin.valueChanged.connect(self.process)
        params_layout.addWidget(self.quality_spin)

        params_layout.addWidget(QLabel(self.tr('Scale:')))
        self.scale_spin = QSpinBox()
        self.scale_spin.setRange(1, 100)
        self.scale_spin.valueChanged.connect(self.process)
        params_layout.addWidget(self.scale_spin)

        self.equalize_check = QCheckBox(self.tr('Equalized'))
        self.equalize_check.stateChanged.connect(self.process)
        params_layout.addWidget(self.equalize_check)

        params_layout.addStretch()
        default_button = QPushButton(self.tr('Default'))
        default_button.clicked.connect(self.default)
        params_layout.addWidget(default_button)

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.default()
        self.process()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #3
0
    def __init__(self, image, parent=None):
        super(EchoWidget, self).__init__(parent)

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Radius:')))
        self.radius_spin = QSpinBox()
        self.radius_spin.setRange(1, 15)
        self.radius_spin.setSuffix(self.tr(' px'))
        self.radius_spin.setValue(2)
        self.radius_spin.valueChanged.connect(self.process)
        params_layout.addWidget(self.radius_spin)

        params_layout.addWidget(QLabel(self.tr('Contrast:')))
        self.contrast_spin = QSpinBox()
        self.contrast_spin.setRange(0, 100)
        self.contrast_spin.setSuffix(self.tr(' %'))
        self.contrast_spin.setValue(85)
        self.contrast_spin.valueChanged.connect(self.process)
        params_layout.addWidget(self.contrast_spin)
        params_layout.addStretch()

        self.image = image
        self.viewer = ImageViewer(self.image, self.image, None)
        self.process()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #4
0
    def __init__(self, image, parent=None):
        super(GradientWidget, self).__init__(parent)
        self.levels_spin = QSpinBox()
        self.levels_spin.setRange(-1, 16)
        self.levels_spin.setSpecialValueText(self.tr('Auto'))
        self.levels_spin.setValue(-1)
        self.invert_check = QCheckBox(self.tr('Invert'))
        self.abs_check = QCheckBox(self.tr('Absolute'))

        self.grad_viewer = ImageViewer(image, image)
        self.image = image
        self.process()

        self.levels_spin.valueChanged.connect(self.process)
        self.invert_check.toggled.connect(self.process)
        self.abs_check.toggled.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Levels:')))
        top_layout.addWidget(self.levels_spin)
        top_layout.addWidget(self.invert_check)
        top_layout.addWidget(self.abs_check)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.grad_viewer)

        self.setLayout(main_layout)
Exemple #5
0
    def __init__(self, image, parent=None):
        super(StatsWidget, self).__init__(parent)

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Mode:')))
        self.min_radio = QRadioButton(self.tr('Minimum'))
        self.min_radio.setChecked(True)
        self.min_radio.toggled.connect(self.process)
        params_layout.addWidget(self.min_radio)
        self.avg_radio = QRadioButton(self.tr('Average'))
        self.avg_radio.toggled.connect(self.process)
        params_layout.addWidget(self.avg_radio)
        self.max_radio = QRadioButton(self.tr('Maximum'))
        self.max_radio.toggled.connect(self.process)
        params_layout.addWidget(self.max_radio)
        self.incl_check = QCheckBox(self.tr('Inclusive'))
        self.incl_check.stateChanged.connect(self.process)
        params_layout.addWidget(self.incl_check)
        params_layout.addStretch()
        help_button = QPushButton()
        help_button.setIcon(QIcon('icons/help.svg'))
        help_button.clicked.connect(self.show_help)
        params_layout.addWidget(help_button)

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.process()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #6
0
    def __init__(self, image, parent=None):
        super(PlanesWidget, self).__init__(parent)

        self.chan_combo = QComboBox()
        self.chan_combo.addItems(
            [self.tr('Luminance'), self.tr('Red'), self.tr('Green'), self.tr('Blue'), self.tr('RGB Norm')])
        self.plane_spin = QSpinBox()
        self.plane_spin.setPrefix(self.tr('Bit '))
        self.plane_spin.setRange(0, 7)
        self.filter_combo = QComboBox()
        self.filter_combo.addItems([self.tr('Disabled'), self.tr('Median'), self.tr('Gaussian')])

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.planes = None
        self.preprocess()

        self.chan_combo.currentIndexChanged.connect(self.preprocess)
        self.plane_spin.valueChanged.connect(self.process)
        self.filter_combo.currentIndexChanged.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Channel:')))
        top_layout.addWidget(self.chan_combo)
        top_layout.addWidget(QLabel(self.tr('Plane:')))
        top_layout.addWidget(self.plane_spin)
        top_layout.addWidget(QLabel(self.tr('Filter:')))
        top_layout.addWidget(self.filter_combo)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #7
0
    def __init__(self, image, parent=None):
        super(MedianWidget, self).__init__(parent)

        self.block_combo = QComboBox()
        self.block_combo.addItems(['16', '32', '64', '128', '256'])
        self.block_combo.setCurrentIndex(2)
        self.block_combo.setToolTip(self.tr('Size of analyzed blocks'))
        self.multi_check = QCheckBox(self.tr('Multi-scale'))
        self.multi_check.setChecked(True)
        self.process_button = QPushButton(self.tr('Process'))

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Block size:')))
        top_layout.addWidget(self.block_combo)
        top_layout.addWidget(self.multi_check)
        top_layout.addWidget(self.process_button)
        top_layout.addStretch()

        self.image = image
        self.gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
        self.viewer = ImageViewer(self.image, self.image)
        self.canceled = False

        self.process_button.clicked.connect(self.process)
        self.block_combo.currentIndexChanged.connect(self.reset)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #8
0
    def __init__(self, image, parent=None):
        super(MinMaxWidget, self).__init__(parent)

        self.chan_combo = QComboBox()
        self.chan_combo.addItems([
            self.tr('Luminance'),
            self.tr('Red'),
            self.tr('Green'),
            self.tr('Blue'),
            self.tr('RGB Norm')
        ])
        colors = [
            self.tr('Red'),
            self.tr('Green'),
            self.tr('Blue'),
            self.tr('White'),
            self.tr('Black')
        ]
        self.process_button = QPushButton(self.tr('Process'))

        self.min_combo = QComboBox()
        self.min_combo.addItems(colors)
        self.min_combo.setCurrentIndex(1)

        self.max_combo = QComboBox()
        self.max_combo.addItems(colors)
        self.max_combo.setCurrentIndex(0)

        self.filter_spin = QSpinBox()
        self.filter_spin.setRange(0, 5)
        self.filter_spin.setSpecialValueText(self.tr('Off'))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.low = self.high = None
        self.stopped = False
        self.change()

        self.process_button.clicked.connect(self.preprocess)
        self.chan_combo.currentIndexChanged.connect(self.change)
        self.min_combo.currentIndexChanged.connect(self.process)
        self.max_combo.currentIndexChanged.connect(self.process)
        self.filter_spin.valueChanged.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Channel:')))
        top_layout.addWidget(self.chan_combo)
        top_layout.addWidget(self.process_button)
        top_layout.addStretch()
        top_layout.addWidget(QLabel(self.tr('Minimum:')))
        top_layout.addWidget(self.min_combo)
        top_layout.addWidget(QLabel(self.tr('Maximum:')))
        top_layout.addWidget(self.max_combo)
        top_layout.addWidget(QLabel(self.tr('Filter:')))
        top_layout.addWidget(self.filter_spin)
        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #9
0
    def __init__(self, image, parent=None):
        super(NoiseWidget, self).__init__(parent)

        self.mode_combo = QComboBox()
        self.mode_combo.addItems([
            self.tr('Median'),
            self.tr('Gaussian'),
            self.tr('BoxBlur'),
            self.tr('Bilateral'),
            self.tr('NonLocal')
        ])

        self.radius_spin = QSpinBox()
        self.radius_spin.setRange(1, 10)
        self.radius_spin.setSuffix(self.tr(' px'))
        self.radius_spin.setValue(1)

        self.sigma_spin = QSpinBox()
        self.sigma_spin.setRange(1, 200)
        self.sigma_spin.setValue(3)

        self.levels_spin = QSpinBox()
        self.levels_spin.setRange(0, 255)
        self.levels_spin.setSpecialValueText(self.tr('Equalized'))
        self.levels_spin.setValue(32)

        self.gray_check = QCheckBox(self.tr('Grayscale'))
        self.denoised_check = QCheckBox(self.tr('Denoised'))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.process()

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Mode:')))
        params_layout.addWidget(self.mode_combo)
        params_layout.addWidget(QLabel(self.tr('Radius:')))
        params_layout.addWidget(self.radius_spin)
        params_layout.addWidget(QLabel(self.tr('Sigma:')))
        params_layout.addWidget(self.sigma_spin)
        params_layout.addWidget(QLabel(self.tr('Levels:')))
        params_layout.addWidget(self.levels_spin)
        params_layout.addWidget(self.gray_check)
        params_layout.addWidget(self.denoised_check)
        params_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)

        self.mode_combo.currentTextChanged.connect(self.process)
        self.radius_spin.valueChanged.connect(self.process)
        self.sigma_spin.valueChanged.connect(self.process)
        self.levels_spin.valueChanged.connect(self.process)
        self.gray_check.stateChanged.connect(self.process)
        self.denoised_check.stateChanged.connect(self.process)
Exemple #10
0
    def __init__(self, image, parent=None):
        super(FrequencyWidget, self).__init__(parent)

        self.ampl_radio = QRadioButton(self.tr('Amplitude'))
        self.ampl_radio.setChecked(True)
        self.phase_radio = QRadioButton(self.tr('Phase'))
        self.dct_radio = QRadioButton(self.tr('DCT Map'))
        self.last_radio = self.ampl_radio
        self.thr_spin = QSpinBox()
        self.thr_spin.setRange(0, 255)
        self.thr_spin.setSpecialValueText(self.tr('Off'))
        self.ratio_label = QLabel()
        self.filter_check = QCheckBox(self.tr('Filter'))

        self.ampl_radio.clicked.connect(self.process)
        self.phase_radio.clicked.connect(self.process)
        self.dct_radio.clicked.connect(self.process)
        self.thr_spin.valueChanged.connect(self.process)
        self.filter_check.stateChanged.connect(self.process)

        gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
        rows, cols = gray.shape
        height = cv.getOptimalDFTSize(rows)
        width = cv.getOptimalDFTSize(cols)
        padded = cv.copyMakeBorder(gray, 0, height - rows, 0, width - cols,
                                   cv.BORDER_CONSTANT).astype(np.float32)
        planes = cv.merge([padded, np.zeros_like(padded)])
        dft = cv.split(np.fft.fftshift(cv.dft(planes)))
        mag, phase = cv.cartToPolar(dft[0], dft[1])
        dct = cv.dct(padded)
        self.result = [
            normalize_mat(img)
            for img in [cv.log(mag), phase, cv.log(dct)]
        ]

        self.image = image
        self.viewer = ImageViewer(self.image, None)
        self.process()

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Coefficients:')))
        top_layout.addWidget(self.ampl_radio)
        top_layout.addWidget(self.phase_radio)
        top_layout.addWidget(self.dct_radio)
        top_layout.addWidget(self.filter_check)
        top_layout.addStretch()
        top_layout.addWidget(QLabel(self.tr('Threshold:')))
        top_layout.addWidget(self.thr_spin)
        top_layout.addWidget(self.ratio_label)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #11
0
    def __init__(self, image, parent=None):
        super(WaveletWidget, self).__init__(parent)

        self.family_combo = QComboBox()
        self.family_combo.addItems([
            self.tr("Daubechies"),
            self.tr("Symlets"),
            self.tr("Coiflets"),
            self.tr("Biorthogonal")
        ])
        self.wavelet_combo = QComboBox()
        self.wavelet_combo.setMinimumWidth(70)
        self.threshold_spin = QSpinBox()
        self.threshold_spin.setRange(0, 100)
        self.threshold_spin.setSuffix("%")
        self.mode_combo = QComboBox()
        self.mode_combo.addItems([
            self.tr("Soft"),
            self.tr("Hard"),
            self.tr("Garrote"),
            self.tr("Greater"),
            self.tr("Less")
        ])
        self.level_spin = QSpinBox()

        self.image = image
        self.coeffs = None
        self.viewer = ImageViewer(self.image, self.image)
        self.update_wavelet()

        self.family_combo.activated.connect(self.update_wavelet)
        self.wavelet_combo.activated.connect(self.update_level)
        self.threshold_spin.valueChanged.connect(self.compute_idwt)
        self.mode_combo.activated.connect(self.compute_idwt)
        self.level_spin.valueChanged.connect(self.compute_idwt)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Family:")))
        top_layout.addWidget(self.family_combo)
        top_layout.addWidget(QLabel(self.tr("Wavelet:")))
        top_layout.addWidget(self.wavelet_combo)
        top_layout.addWidget(QLabel(self.tr("Threshold:")))
        top_layout.addWidget(self.threshold_spin)
        top_layout.addWidget(QLabel(self.tr("Mode:")))
        top_layout.addWidget(self.mode_combo)
        top_layout.addWidget(QLabel(self.tr("Level:")))
        top_layout.addWidget(self.level_spin)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #12
0
    def __init__(self, image, parent=None):
        super(ElaWidget, self).__init__(parent)

        self.quality_spin = QSpinBox()
        self.quality_spin.setRange(1, 100)
        self.quality_spin.setSuffix(self.tr(' %'))
        self.quality_spin.setToolTip(self.tr('JPEG reference quality level'))
        self.scale_spin = QSpinBox()
        self.scale_spin.setRange(1, 100)
        self.scale_spin.setSuffix(' %')
        self.scale_spin.setToolTip(self.tr('Output multiplicative gain'))
        self.contrast_spin = QSpinBox()
        self.contrast_spin.setRange(0, 100)
        self.contrast_spin.setSuffix(' %')
        self.contrast_spin.setToolTip(self.tr('Output tonality compression'))
        self.linear_check = QCheckBox(self.tr('Linear'))
        self.linear_check.setToolTip(self.tr('Linearize absolute difference'))
        self.gray_check = QCheckBox(self.tr('Grayscale'))
        self.gray_check.setToolTip(self.tr('Desaturated output'))
        default_button = QPushButton(self.tr('Default'))
        default_button.setToolTip(self.tr('Revert to default parameters'))

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Quality:')))
        params_layout.addWidget(self.quality_spin)
        params_layout.addWidget(QLabel(self.tr('Scale:')))
        params_layout.addWidget(self.scale_spin)
        params_layout.addWidget(QLabel(self.tr('Contrast:')))
        params_layout.addWidget(self.contrast_spin)
        params_layout.addWidget(self.linear_check)
        params_layout.addWidget(self.gray_check)
        params_layout.addWidget(default_button)
        params_layout.addStretch()

        self.image = image
        self.original = image.astype(np.float32) / 255
        self.compressed = None
        self.viewer = ImageViewer(self.image, self.image)
        self.default()

        self.quality_spin.valueChanged.connect(self.preprocess)
        self.scale_spin.valueChanged.connect(self.process)
        self.contrast_spin.valueChanged.connect(self.process)
        self.linear_check.stateChanged.connect(self.process)
        self.gray_check.stateChanged.connect(self.process)
        default_button.clicked.connect(self.default)

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #13
0
    def __init__(self, image, parent=None):
        super(GradientWidget, self).__init__(parent)
        self.intensity_spin = QSpinBox()
        self.intensity_spin.setRange(0, 100)
        self.intensity_spin.setValue(95)
        self.intensity_spin.setSuffix(self.tr(" %"))
        self.intensity_spin.setToolTip(self.tr("Tonality compression amount"))
        self.blue_combo = QComboBox()
        self.blue_combo.addItems([
            self.tr("None"),
            self.tr("Flat"),
            self.tr("Abs"),
            self.tr("Norm")
        ])
        self.blue_combo.setCurrentIndex(2)
        self.blue_combo.setToolTip(self.tr("Blue component inclusion mode"))
        self.invert_check = QCheckBox(self.tr("Invert"))
        self.invert_check.setToolTip(self.tr("Reverse lighting direction"))
        self.equalize_check = QCheckBox(self.tr("Equalize"))
        self.equalize_check.setToolTip(self.tr("Apply histogram equalization"))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.dx, self.dy = cv.spatialGradient(
            cv.cvtColor(self.image, cv.COLOR_BGR2GRAY))
        self.process()

        self.intensity_spin.valueChanged.connect(self.process)
        self.blue_combo.currentIndexChanged.connect(self.process)
        self.invert_check.stateChanged.connect(self.process)
        self.equalize_check.stateChanged.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Intensity:")))
        top_layout.addWidget(self.intensity_spin)
        top_layout.addWidget(QLabel(self.tr("Blue channel:")))
        top_layout.addWidget(self.blue_combo)
        top_layout.addWidget(self.invert_check)
        top_layout.addWidget(self.equalize_check)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)

        self.setLayout(main_layout)
Exemple #14
0
    def __init__(self, image, parent=None):
        super(WaveletWidget, self).__init__(parent)

        self.family_combo = QComboBox()
        self.family_combo.addItems(
            [self.tr('Daubechies'), self.tr('Symlets'), self.tr('Coiflets'), self.tr('Biorthogonal')])
        self.wavelet_combo = QComboBox()
        self.wavelet_combo.setMinimumWidth(70)
        self.threshold_spin = QSpinBox()
        self.threshold_spin.setRange(0, 100)
        self.threshold_spin.setSuffix('%')
        self.mode_combo = QComboBox()
        self.mode_combo.addItems(
            [self.tr('Soft'), self.tr('Hard'), self.tr('Garrote'), self.tr('Greater'), self.tr('Less')])
        self.level_spin = QSpinBox()

        self.image = image
        self.coeffs = None
        self.viewer = ImageViewer(self.image, self.image)
        self.update_wavelet()

        self.family_combo.activated.connect(self.update_wavelet)
        self.wavelet_combo.activated.connect(self.update_level)
        self.threshold_spin.valueChanged.connect(self.compute_idwt)
        self.mode_combo.activated.connect(self.compute_idwt)
        self.level_spin.valueChanged.connect(self.compute_idwt)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Family:')))
        top_layout.addWidget(self.family_combo)
        top_layout.addWidget(QLabel(self.tr('Wavelet:')))
        top_layout.addWidget(self.wavelet_combo)
        top_layout.addWidget(QLabel(self.tr('Threshold:')))
        top_layout.addWidget(self.threshold_spin)
        top_layout.addWidget(QLabel(self.tr('Mode:')))
        top_layout.addWidget(self.mode_combo)
        top_layout.addWidget(QLabel(self.tr('Level:')))
        top_layout.addWidget(self.level_spin)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #15
0
    def __init__(self, image, parent=None):
        super(MedianWidget, self).__init__(parent)

        self.variance_spin = QSpinBox()
        self.variance_spin.setRange(0, 50)
        self.variance_spin.setValue(10)
        self.threshold_spin = QDoubleSpinBox()
        self.threshold_spin.setRange(0, 1)
        self.threshold_spin.setValue(0.45)
        self.threshold_spin.setSingleStep(0.01)
        self.showprob_check = QCheckBox(self.tr('Probability map'))
        self.filter_check = QCheckBox(self.tr('Speckle filter'))
        self.filter_check.setChecked(True)
        self.process_button = QPushButton(self.tr('Process'))
        self.avgprob_label = QLabel(self.tr('Press "Process" to start'))

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Min variance:')))
        top_layout.addWidget(self.variance_spin)
        top_layout.addWidget(QLabel(self.tr('Threshold:')))
        top_layout.addWidget(self.threshold_spin)
        top_layout.addWidget(self.showprob_check)
        top_layout.addWidget(self.filter_check)
        top_layout.addWidget(self.process_button)
        # top_layout.addWidget(self.avgprob_label)
        top_layout.addStretch()

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
        self.prob = self.var = None
        self.block = 64
        self.canceled = False

        self.process_button.clicked.connect(self.prepare)
        self.variance_spin.valueChanged.connect(self.process)
        self.threshold_spin.valueChanged.connect(self.process)
        self.showprob_check.stateChanged.connect(self.process)
        self.filter_check.stateChanged.connect(self.process)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #16
0
    def __init__(self, image, parent=None):
        super(ContrastWidget, self).__init__(parent)

        self.algo_combo = QComboBox()
        self.algo_combo.addItems([
            self.tr("Histogram Error"),
            self.tr("Channel Similarity"),
            self.tr("Joint probability")
        ])
        self.algo_combo.setToolTip(
            self.
            tr("Joint Probability merges Histogram Error and Channel Similarity"
               ))
        self.algo_combo.setCurrentIndex(2)
        self.block_combo = QComboBox()
        self.block_combo.addItems(["32", "64", "128", "256"])
        self.block_combo.setCurrentIndex(1)
        self.block_combo.setToolTip(self.tr("Size of analyzed blocks"))
        self.process_button = QPushButton(self.tr("Process"))
        self.process_button.setToolTip(
            self.tr("Perform contrast enhancement analysis"))

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Algorithm:")))
        top_layout.addWidget(self.algo_combo)
        top_layout.addWidget(QLabel(self.tr("Block size:")))
        top_layout.addWidget(self.block_combo)
        top_layout.addWidget(self.process_button)
        top_layout.addStretch()

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.error = self.chsim = self.joint = None
        self.canceled = False

        self.process_button.clicked.connect(self.process)
        self.algo_combo.currentIndexChanged.connect(self.choose)
        self.block_combo.currentIndexChanged.connect(self.reset)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #17
0
    def __init__(self, filename, image, parent=None):
        super(ThumbWidget, self).__init__(parent)

        temp_file = QTemporaryFile()
        if temp_file.open():
            output = subprocess.check_output(
                [exiftool_exe(), '-b', '-ThumbnailImage', filename])
            temp_name = temp_file.fileName()
            with open(temp_name, 'wb') as file:
                file.write(output)
            thumb = cv.imread(temp_name, cv.IMREAD_COLOR)
            if thumb is None:
                self.show_error(self.tr('Thumbnail image not found!'))
                return
            # resized = cv.resize(image, thumb.shape[:-1][::-1], interpolation=cv.INTER_AREA)
            resized = cv.resize(thumb,
                                image.shape[:-1][::-1],
                                interpolation=cv.INTER_LANCZOS4)
            diff = cv.absdiff(image, resized)

            # image_aspect = image.shape[1] / image.shape[0]
            # thumb_aspect = thumb.shape[1] / thumb.shape[0]
            # if thumb_aspect < image_aspect:
            #     shape = (thumb.shape[1] // image_aspect, thumb.shape[1])
            # elif thumb_aspect > image_aspect:
            #     shape = (thumb.shape[0], thumb.shape[0] * image_aspect)
            # else:
            #     shape = thumb.shape
            # resized = cv.resize(image, shape, None, 0, 0, interpolation=cv.INTER_AREA)
            # top = (thumb.shape[0] - resized.shape[0]) / 2
            # bottom = top
            # left = (thumb.shape[1] - resized.shape[1]) / 2
            # right = left
            # padded = cv.copyMakeBorder(resized, top, bottom, left, right, cv.BORDER_CONSTANT)
            # if padded.shape != thumb.shape:
            #     padded = cv.resize(padded, thumb.shape, interpolation=cv.INTER_AREA)
            # diff = cv.cvtColor(cv.absdiff(thumb, padded), cv.COLOR_BGR2GRAY)

            viewer = ImageViewer(resized, diff)
            layout = QVBoxLayout()
            layout.addWidget(viewer)
            self.setLayout(layout)
Exemple #18
0
    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)

        self.cntr, self.numImages = -1, -1  # self.cntr have the info of which image is selected/displayed

        self.image_viewer = ImageViewer(self.qlabel_image)
        self.__connectEvents()
        self.showMaximized()
        self.videoFrameCount = -1
        self.videoLoaded = False
        self.vidlength = -1
        self.nameItemDict = {}
        self.dataset = None
        
        self.imagesList = {}
        self.folder = None
        self.locked = True

        self.refreshLabels()
Exemple #19
0
    def __init__(self, image, parent=None):
        super(MagnifierWidget, self).__init__(parent)

        self.equalize_radio = QRadioButton(self.tr("Equalization"))
        self.equalize_radio.setToolTip(self.tr("RGB histogram equalization"))
        self.contrast_radio = QRadioButton(self.tr("Auto Contrast"))
        self.contrast_radio.setToolTip(self.tr("Compress luminance tonality"))
        self.centile_spin = QSpinBox()
        self.centile_spin.setRange(0, 100)
        self.centile_spin.setValue(20)
        self.centile_spin.setSuffix(self.tr(" %"))
        self.centile_spin.setToolTip(self.tr("Histogram percentile amount"))
        self.channel_check = QCheckBox(self.tr("By channel"))
        self.channel_check.setToolTip(self.tr("Independent RGB compression"))
        self.equalize_radio.setChecked(True)
        self.last_radio = self.equalize_radio

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.change()

        self.viewer.viewChanged.connect(self.process)
        self.equalize_radio.clicked.connect(self.change)
        self.contrast_radio.clicked.connect(self.change)
        self.centile_spin.valueChanged.connect(self.change)
        self.channel_check.stateChanged.connect(self.change)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Mode:")))
        top_layout.addWidget(self.equalize_radio)
        top_layout.addWidget(self.contrast_radio)
        top_layout.addWidget(self.centile_spin)
        top_layout.addWidget(self.channel_check)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #20
0
    def __init__(self, image, parent=None):
        super(MagnifierWidget, self).__init__(parent)

        self.equalize_radio = QRadioButton(self.tr('Equalization'))
        self.contrast_radio = QRadioButton(self.tr('Auto Contrast'))
        self.retinex_radio = QRadioButton(self.tr('Human Retina'))
        self.centile_spin = QSpinBox()
        self.centile_spin.setRange(0, 100)
        self.centile_spin.setValue(20)
        self.centile_spin.setSuffix(self.tr(' %'))
        self.channel_check = QCheckBox(self.tr('By channel'))
        self.equalize_radio.setChecked(True)
        self.last_radio = self.equalize_radio

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.change()

        self.viewer.view_changed.connect(self.process)
        self.equalize_radio.toggled.connect(self.change)
        self.contrast_radio.toggled.connect(self.change)
        self.centile_spin.valueChanged.connect(self.change)
        self.channel_check.stateChanged.connect(self.change)
        self.retinex_radio.toggled.connect(self.change)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Enhancement:')))
        top_layout.addWidget(self.equalize_radio)
        top_layout.addWidget(self.contrast_radio)
        top_layout.addWidget(self.centile_spin)
        top_layout.addWidget(self.channel_check)
        top_layout.addWidget(self.retinex_radio)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #21
0
    def __init__(self, image, parent=None):
        super(EchoWidget, self).__init__(parent)

        self.radius_spin = QSpinBox()
        self.radius_spin.setRange(1, 15)
        self.radius_spin.setSuffix(self.tr(" px"))
        self.radius_spin.setValue(2)
        self.radius_spin.setToolTip(self.tr("Laplacian filter radius"))

        self.contrast_spin = QSpinBox()
        self.contrast_spin.setRange(0, 100)
        self.contrast_spin.setSuffix(self.tr(" %"))
        self.contrast_spin.setValue(85)
        self.contrast_spin.setToolTip(self.tr("Output tonality compression"))

        self.gray_check = QCheckBox(self.tr("Grayscale"))
        self.gray_check.setToolTip(self.tr("Desaturated output mode"))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image, None)
        self.process()

        self.radius_spin.valueChanged.connect(self.process)
        self.contrast_spin.valueChanged.connect(self.process)
        self.gray_check.stateChanged.connect(self.process)

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr("Radius:")))
        params_layout.addWidget(self.radius_spin)
        params_layout.addWidget(QLabel(self.tr("Contrast:")))
        params_layout.addWidget(self.contrast_spin)
        params_layout.addWidget(self.gray_check)
        params_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #22
0
    def __init__(self, image, parent=None):
        super(GradientWidget, self).__init__(parent)
        self.intensity_spin = QSpinBox()
        self.intensity_spin.setRange(0, 127)
        self.intensity_spin.setValue(90)
        self.blue_combo = QComboBox()
        self.blue_combo.addItems(
            [self.tr('None'),
             self.tr('Flat'),
             self.tr('Norm')])
        self.invert_check = QCheckBox(self.tr('Invert'))
        self.equalize_check = QCheckBox(self.tr('Equalize'))

        self.grad_viewer = ImageViewer(image, image)
        self.image = image
        self.process()

        self.intensity_spin.valueChanged.connect(self.process)
        self.blue_combo.currentIndexChanged.connect(self.process)
        self.invert_check.stateChanged.connect(self.process)
        self.equalize_check.stateChanged.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Intensity:')))
        top_layout.addWidget(self.intensity_spin)
        top_layout.addWidget(QLabel(self.tr('Blue channel:')))
        top_layout.addWidget(self.blue_combo)
        top_layout.addWidget(self.invert_check)
        top_layout.addWidget(self.equalize_check)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.grad_viewer)

        self.setLayout(main_layout)
Exemple #23
0
    def __init__(self, image, parent=None):
        super(FrequencyWidget, self).__init__(parent)

        self.split_spin = QSpinBox()
        self.split_spin.setRange(0, 100)
        self.split_spin.setValue(15)
        self.split_spin.setSuffix(self.tr(" %"))

        self.smooth_spin = QSpinBox()
        self.smooth_spin.setRange(0, 100)
        self.smooth_spin.setValue(25)
        self.smooth_spin.setSuffix(self.tr(" %"))
        self.smooth_spin.setSpecialValueText(self.tr("Off"))

        self.thr_spin = QSpinBox()
        self.thr_spin.setRange(0, 100)
        self.thr_spin.setValue(0)
        self.thr_spin.setSuffix(self.tr(" %"))
        self.thr_spin.setSpecialValueText(self.tr("Off"))

        self.zero_label = QLabel()
        modify_font(self.zero_label, italic=True)

        self.filter_spin = QSpinBox()
        self.filter_spin.setRange(0, 15)
        self.filter_spin.setValue(0)
        self.filter_spin.setSuffix(self.tr(" px"))
        self.filter_spin.setSpecialValueText(self.tr("Off"))

        self.split_spin.valueChanged.connect(self.process)
        self.smooth_spin.valueChanged.connect(self.process)
        self.thr_spin.valueChanged.connect(self.process)
        self.filter_spin.valueChanged.connect(self.postprocess)

        self.image = image
        gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
        rows, cols = gray.shape
        height = cv.getOptimalDFTSize(rows)
        width = cv.getOptimalDFTSize(cols)
        padded = cv.copyMakeBorder(gray, 0, height - rows, 0, width - cols, cv.BORDER_CONSTANT)
        self.dft = np.fft.fftshift(cv.dft(padded.astype(np.float32), flags=cv.DFT_COMPLEX_OUTPUT))
        self.magnitude0, self.phase0 = cv.cartToPolar(self.dft[:, :, 0], self.dft[:, :, 1])
        self.magnitude0 = cv.normalize(cv.log(self.magnitude0), None, 0, 255, cv.NORM_MINMAX)
        self.phase0 = cv.normalize(self.phase0, None, 0, 255, cv.NORM_MINMAX)
        self.magnitude = self.phase = None

        self.low_viewer = ImageViewer(self.image, self.image, self.tr("Low frequency"), export=True)
        self.high_viewer = ImageViewer(self.image, self.image, self.tr("High frequency"), export=True)
        self.mag_viewer = ImageViewer(self.image, None, self.tr("DFT Magnitude"), export=True)
        self.phase_viewer = ImageViewer(self.image, None, self.tr("DFT Phase"), export=True)
        self.process()

        self.low_viewer.viewChanged.connect(self.high_viewer.changeView)
        self.high_viewer.viewChanged.connect(self.low_viewer.changeView)
        self.mag_viewer.viewChanged.connect(self.phase_viewer.changeView)
        self.phase_viewer.viewChanged.connect(self.mag_viewer.changeView)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Separation:")))
        top_layout.addWidget(self.split_spin)
        top_layout.addWidget(QLabel(self.tr("Smooth:")))
        top_layout.addWidget(self.smooth_spin)
        top_layout.addWidget(QLabel(self.tr("Threshold:")))
        top_layout.addWidget(self.thr_spin)
        top_layout.addWidget(QLabel(self.tr("Filter:")))
        top_layout.addWidget(self.filter_spin)
        top_layout.addWidget(self.zero_label)
        top_layout.addStretch()

        center_layout = QGridLayout()
        center_layout.addWidget(self.low_viewer, 0, 0)
        center_layout.addWidget(self.high_viewer, 0, 1)
        center_layout.addWidget(self.mag_viewer, 1, 0)
        center_layout.addWidget(self.phase_viewer, 1, 1)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addLayout(center_layout)
        self.setLayout(main_layout)
Exemple #24
0
    def __init__(self, image, parent=None):
        super(PcaWidget, self).__init__(parent)

        self.component_combo = QComboBox()
        self.component_combo.addItems([self.tr(f"#{i + 1}") for i in range(3)])
        self.distance_radio = QRadioButton(self.tr("Distance"))
        self.distance_radio.setToolTip(self.tr("Distance from the closest point on selected component"))
        self.project_radio = QRadioButton(self.tr("Projection"))
        self.project_radio.setToolTip(self.tr("Projection onto the selected principal component"))
        self.crossprod_radio = QRadioButton(self.tr("Cross product"))
        self.crossprod_radio.setToolTip(self.tr("Cross product between input and selected component"))
        self.distance_radio.setChecked(True)
        self.last_radio = self.distance_radio
        self.invert_check = QCheckBox(self.tr("Invert"))
        self.invert_check.setToolTip(self.tr("Output bitwise complement"))
        self.equalize_check = QCheckBox(self.tr("Equalize"))
        self.equalize_check.setToolTip(self.tr("Apply histogram equalization"))

        rows, cols, chans = image.shape
        x = np.reshape(image, (rows * cols, chans)).astype(np.float32)
        mu, ev, ew = cv.PCACompute2(x, np.array([]))
        p = np.reshape(cv.PCAProject(x, mu, ev), (rows, cols, chans))
        x0 = image.astype(np.float32) - mu
        self.output = []
        for i, v in enumerate(ev):
            cross = np.cross(x0, v)
            distance = np.linalg.norm(cross, axis=2) / np.linalg.norm(v)
            project = p[:, :, i]
            self.output.extend([norm_mat(distance, to_bgr=True), norm_mat(project, to_bgr=True), norm_img(cross)])

        table_data = [
            [mu[0, 2], mu[0, 1], mu[0, 0]],
            [ev[0, 2], ev[0, 1], ev[0, 0]],
            [ev[1, 2], ev[1, 1], ev[1, 0]],
            [ev[2, 2], ev[2, 1], ev[2, 0]],
            [ew[2, 0], ew[1, 0], ew[0, 0]],
        ]
        table_widget = QTableWidget(5, 4)
        table_widget.setHorizontalHeaderLabels([self.tr("Element"), self.tr("Red"), self.tr("Green"), self.tr("Blue")])
        table_widget.setItem(0, 0, QTableWidgetItem(self.tr("Mean vector")))
        table_widget.setItem(1, 0, QTableWidgetItem(self.tr("Eigenvector 1")))
        table_widget.setItem(2, 0, QTableWidgetItem(self.tr("Eigenvector 2")))
        table_widget.setItem(3, 0, QTableWidgetItem(self.tr("Eigenvector 3")))
        table_widget.setItem(4, 0, QTableWidgetItem(self.tr("Eigenvalues")))
        for i in range(len(table_data)):
            modify_font(table_widget.item(i, 0), bold=True)
            for j in range(len(table_data[i])):
                table_widget.setItem(i, j + 1, QTableWidgetItem(str(table_data[i][j])))
        # item = QTableWidgetItem()
        # item.setBackgroundColor(QColor(mu[0, 2], mu[0, 1], mu[0, 0]))
        # table_widget.setItem(0, 4, item)
        # table_widget.resizeRowsToContents()
        # table_widget.resizeColumnsToContents()
        table_widget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        table_widget.setSelectionMode(QAbstractItemView.SingleSelection)
        table_widget.setMaximumHeight(190)

        self.viewer = ImageViewer(image, image, None)
        self.process()

        self.component_combo.currentIndexChanged.connect(self.process)
        self.distance_radio.clicked.connect(self.process)
        self.project_radio.clicked.connect(self.process)
        self.crossprod_radio.clicked.connect(self.process)
        self.invert_check.stateChanged.connect(self.process)
        self.equalize_check.stateChanged.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Component:")))
        top_layout.addWidget(self.component_combo)
        top_layout.addWidget(QLabel(self.tr("Mode:")))
        top_layout.addWidget(self.distance_radio)
        top_layout.addWidget(self.project_radio)
        top_layout.addWidget(self.crossprod_radio)
        top_layout.addWidget(self.invert_check)
        top_layout.addWidget(self.equalize_check)
        top_layout.addStretch()
        bottom_layout = QHBoxLayout()
        bottom_layout.addWidget(table_widget)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        main_layout.addLayout(bottom_layout)
        self.setLayout(main_layout)
Exemple #25
0
    def __init__(self, image, parent=None):
        super(StereoWidget, self).__init__(parent)

        gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
        small = cv.resize(gray, None, None, 1, 0.5)
        start = 10
        end = small.shape[1] // 3
        diff = np.fromiter([
            cv.mean(cv.absdiff(small[:, i:], small[:, :-i]))[0]
            for i in range(start, end)
        ], np.float32)
        _, maximum, _, argmax = cv.minMaxLoc(np.ediff1d(diff))
        if maximum < 2:
            error_label = QLabel(self.tr("Unable to detect stereogram!"))
            modify_font(error_label, bold=True)
            error_label.setStyleSheet("color: #FF0000")
            error_label.setAlignment(Qt.AlignCenter)
            main_layout = QVBoxLayout()
            main_layout.addWidget(error_label)
            self.setLayout(main_layout)
            return

        offset = argmax[1] + start
        a = image[:, offset:]
        b = image[:, :-offset]
        self.pattern = norm_img(cv.absdiff(a, b))
        temp = cv.cvtColor(self.pattern, cv.COLOR_BGR2GRAY)
        thr, _ = cv.threshold(temp, 0, 255, cv.THRESH_TRIANGLE)
        self.silhouette = cv.medianBlur(
            gray_to_bgr(cv.threshold(temp, thr, 255, cv.THRESH_BINARY)[1]), 3)
        a = cv.cvtColor(a, cv.COLOR_BGR2GRAY)
        b = cv.cvtColor(b, cv.COLOR_BGR2GRAY)
        flow = cv.calcOpticalFlowFarneback(a, b, None, 0.5, 5, 15, 5, 5, 1.2,
                                           cv.OPTFLOW_FARNEBACK_GAUSSIAN)[:, :,
                                                                          0]
        self.depth = gray_to_bgr(norm_mat(flow))
        flow = np.repeat(cv.normalize(flow, None, 0, 1,
                                      cv.NORM_MINMAX)[:, :, np.newaxis],
                         3,
                         axis=2)
        self.shaded = cv.normalize(
            self.pattern.astype(np.float32) * flow, None, 0, 255,
            cv.NORM_MINMAX).astype(np.uint8)
        self.viewer = ImageViewer(self.pattern, None, export=True)

        self.pattern_radio = QRadioButton(self.tr("Pattern"))
        self.pattern_radio.setChecked(True)
        self.pattern_radio.setToolTip(
            self.tr("Difference between raw and aligned image"))
        self.silhouette_radio = QRadioButton(self.tr("Silhouette"))
        self.silhouette_radio.setToolTip(
            self.tr("Apply threshold to discovered pattern"))
        self.depth_radio = QRadioButton(self.tr("Depth"))
        self.depth_radio.setToolTip(
            self.tr("Estimate 3D depth using optical flow"))
        self.shaded_radio = QRadioButton(self.tr("Shaded"))
        self.shaded_radio.setToolTip(
            self.tr("Combine pattern and depth information"))

        self.silhouette_radio.clicked.connect(self.process)
        self.pattern_radio.clicked.connect(self.process)
        self.depth_radio.clicked.connect(self.process)
        self.shaded_radio.clicked.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr("Mode:")))
        top_layout.addWidget(self.pattern_radio)
        top_layout.addWidget(self.silhouette_radio)
        top_layout.addWidget(self.depth_radio)
        top_layout.addWidget(self.shaded_radio)
        top_layout.addStretch()
        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #26
0
    def __init__(self, image, parent=None):
        super(StatsWidget, self).__init__(parent)

        self.min_radio = QRadioButton(self.tr('Minimum'))
        self.min_radio.setToolTip(self.tr('RGB channel with smallest value'))
        self.min_radio.setChecked(True)
        self.avg_radio = QRadioButton(self.tr('Average'))
        self.avg_radio.setToolTip(self.tr('RGB channel with average value'))
        self.max_radio = QRadioButton(self.tr('Maximum'))
        self.max_radio.setToolTip(self.tr('RGB channel with largest value'))
        self.incl_check = QCheckBox(self.tr('Inclusive'))
        self.incl_check.setToolTip(self.tr('Use not strict inequalities'))

        self.image = image
        b, g, r = cv.split(self.image)
        blue = np.array([255, 0, 0])
        green = np.array([0, 255, 0])
        red = np.array([0, 0, 255])
        self.minimum = [[], []]
        self.minimum[0] = np.zeros_like(self.image)
        self.minimum[0][np.logical_and(b < g, b < r)] = blue
        self.minimum[0][np.logical_and(g < r, g < b)] = green
        self.minimum[0][np.logical_and(r < b, r < g)] = red
        self.minimum[1] = np.zeros_like(self.image)
        self.minimum[1][np.logical_and(b <= g, b <= r)] = blue
        self.minimum[1][np.logical_and(g <= r, g <= b)] = green
        self.minimum[1][np.logical_and(r <= b, r <= g)] = red
        self.maximum = [[], []]
        self.maximum[0] = np.zeros_like(self.image)
        self.maximum[0][np.logical_and(b > g, b > r)] = blue
        self.maximum[0][np.logical_and(g > r, g > b)] = green
        self.maximum[0][np.logical_and(r > b, r > g)] = red
        self.maximum[1] = np.zeros_like(self.image)
        self.maximum[1][np.logical_and(b >= g, b >= r)] = blue
        self.maximum[1][np.logical_and(g >= r, g >= b)] = green
        self.maximum[1][np.logical_and(r >= b, r >= g)] = red
        self.average = [[], []]
        self.average[0] = np.zeros_like(self.image)
        self.average[0][np.logical_or(np.logical_and(r < b, b < g),
                                      np.logical_and(g < b, b < r))] = blue
        self.average[0][np.logical_or(np.logical_and(r < g, g < b),
                                      np.logical_and(b < g, g < r))] = green
        self.average[0][np.logical_or(np.logical_and(b < r, r < g),
                                      np.logical_and(g < r, r < b))] = red
        self.average[1] = np.zeros_like(self.image)
        self.average[1][np.logical_or(np.logical_and(r <= b, b <= g),
                                      np.logical_and(g <= b, b <= r))] = blue
        self.average[1][np.logical_or(np.logical_and(r <= g, g <= b),
                                      np.logical_and(b <= g, g <= r))] = green
        self.average[1][np.logical_or(np.logical_and(b <= r, r <= g),
                                      np.logical_and(g <= r, r <= b))] = red
        self.viewer = ImageViewer(self.image, self.image)
        self.process()

        self.min_radio.clicked.connect(self.process)
        self.avg_radio.clicked.connect(self.process)
        self.max_radio.clicked.connect(self.process)
        self.incl_check.stateChanged.connect(self.process)

        params_layout = QHBoxLayout()
        params_layout.addWidget(QLabel(self.tr('Mode:')))
        params_layout.addWidget(self.min_radio)
        params_layout.addWidget(self.avg_radio)
        params_layout.addWidget(self.max_radio)
        params_layout.addWidget(self.incl_check)
        params_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(params_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #27
0
    def __init__(self, image, parent=None):
        super(AdjustWidget, self).__init__(parent)

        self.bright_slider = ParamSlider([-255, +255], 16, 0)
        self.sat_slider = ParamSlider([-255, +255], 16, 0)
        self.hue_slider = ParamSlider([0, 180], 10, 0, '°')
        self.gamma_slider = ParamSlider([1, 50], 10, 10)
        self.shadow_slider = ParamSlider([-100, +100], 10, 0, '%')
        self.high_slider = ParamSlider([-100, +100], 10, 0, '%')
        self.sweep_slider = ParamSlider([0, 255], 8, 127)
        self.width_slider = ParamSlider([0, 255], 8, 255)
        self.thr_slider = ParamSlider([0, 255], 16, 255)
        self.equalize_combo = QComboBox()
        self.equalize_combo.addItems([
            self.tr('No equalization'),
            self.tr('Histogram EQ'),
            self.tr('Weak CLAHE'),
            self.tr('Medium CLAHE'),
            self.tr('Strong CLAHE'),
            self.tr('Extreme CLAHE')
        ])
        self.invert_check = QCheckBox(self.tr('Invert values'))
        self.reset_button = QPushButton(self.tr('Reset'))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.process()

        self.bright_slider.valueChanged.connect(self.process)
        self.sat_slider.valueChanged.connect(self.process)
        self.hue_slider.valueChanged.connect(self.process)
        self.gamma_slider.valueChanged.connect(self.process)
        self.shadow_slider.valueChanged.connect(self.process)
        self.high_slider.valueChanged.connect(self.process)
        self.sweep_slider.valueChanged.connect(self.process)
        self.width_slider.valueChanged.connect(self.process)
        self.thr_slider.valueChanged.connect(self.process)
        self.equalize_combo.currentIndexChanged.connect(self.process)
        self.invert_check.stateChanged.connect(self.process)
        self.reset_button.clicked.connect(self.reset)

        params_layout = QGridLayout()
        params_layout.addWidget(QLabel(self.tr('Brightness')), 0, 0)
        params_layout.addWidget(QLabel(self.tr('Saturation')), 1, 0)
        params_layout.addWidget(QLabel(self.tr('Hue')), 2, 0)
        params_layout.addWidget(self.bright_slider, 0, 1)
        params_layout.addWidget(self.sat_slider, 1, 1)
        params_layout.addWidget(self.hue_slider, 2, 1)
        params_layout.addWidget(QLabel(self.tr('Gamma')), 0, 2)
        params_layout.addWidget(QLabel(self.tr('Shadows')), 1, 2)
        params_layout.addWidget(QLabel(self.tr('Highlights')), 2, 2)
        params_layout.addWidget(self.gamma_slider, 0, 3)
        params_layout.addWidget(self.shadow_slider, 1, 3)
        params_layout.addWidget(self.high_slider, 2, 3)
        params_layout.addWidget(QLabel(self.tr('Sweep')), 0, 4)
        params_layout.addWidget(QLabel(self.tr('Width')), 1, 4)
        params_layout.addWidget(QLabel(self.tr('Threshold')), 2, 4)
        params_layout.addWidget(self.sweep_slider, 0, 5)
        params_layout.addWidget(self.width_slider, 1, 5)
        params_layout.addWidget(self.thr_slider, 2, 5)
        params_layout.addWidget(self.equalize_combo, 0, 6)
        params_layout.addWidget(self.invert_check, 1, 6)
        params_layout.addWidget(self.reset_button, 2, 6)
        top_layout = QHBoxLayout()
        top_layout.addLayout(params_layout)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #28
0
    def __init__(self, image, parent=None):
        super(PcaWidget, self).__init__(parent)

        self.comp_combo = QComboBox()
        self.comp_combo.addItems([self.tr('#{}'.format(i + 1)) for i in range(3)])

        self.distvect_radio = QRadioButton(self.tr('Vector Distance'))
        self.cross_radio = QRadioButton(self.tr('Cross Correlation'))
        self.distvect_radio.setChecked(True)
        self.last_radio = self.distvect_radio

        self.image = image
        self.components = []
        rows, cols, dims = self.image.shape
        bgr = np.reshape(self.image, (rows * cols, dims)).astype(np.float32)
        m, eigen_vec, eigen_val = cv.PCACompute2(bgr, np.array([]))
        p = self.image.astype(np.float32) - m
        for v in eigen_vec:
            c = np.cross(p, v)
            d = np.linalg.norm(c, axis=2) / np.linalg.norm(v)
            distance = normalize_mat(d, to_bgr=True)
            cross = cv.merge([normalize_mat(x) for x in cv.split(c)])
            self.components.extend([distance, cross])

        table_data = [[m[0, 2], m[0, 1], m[0, 0]],
                      [eigen_vec[0, 2], eigen_vec[0, 1], eigen_vec[0, 0]],
                      [eigen_vec[1, 2], eigen_vec[1, 1], eigen_vec[1, 0]],
                      [eigen_vec[2, 2], eigen_vec[2, 1], eigen_vec[2, 0]],
                      [eigen_val[2, 0], eigen_val[1, 0], eigen_val[0, 0]]]
        table_widget = QTableWidget(5, 4)
        table_widget.setHorizontalHeaderLabels([
            self.tr('Element'), self.tr('Red'), self.tr('Green'), self.tr('Blue')])
        table_widget.setItem(0, 0, QTableWidgetItem(self.tr('Mean color')))
        table_widget.setItem(1, 0, QTableWidgetItem(self.tr('Eigen vect 1')))
        table_widget.setItem(2, 0, QTableWidgetItem(self.tr('Eigen vect 2')))
        table_widget.setItem(3, 0, QTableWidgetItem(self.tr('Eigen vect 3')))
        table_widget.setItem(4, 0, QTableWidgetItem(self.tr('Eigen values')))
        for i in range(len(table_data)):
            modify_font(table_widget.item(i, 0), bold=True)
            for j in range(len(table_data[i])):
                table_widget.setItem(i, j + 1, QTableWidgetItem(str(table_data[i][j])))
        # item = QTableWidgetItem()
        # item.setBackgroundColor(QColor(m[0, 2], m[0, 1], m[0, 0]))
        # table_widget.setItem(0, 4, item)
        # table_widget.resizeRowsToContents()
        # table_widget.resizeColumnsToContents()
        table_widget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        table_widget.setSelectionMode(QAbstractItemView.SingleSelection)
        table_widget.setMaximumHeight(190)

        self.viewer = ImageViewer(self.image, self.image, None)
        self.process()

        self.comp_combo.currentIndexChanged.connect(self.process)
        self.distvect_radio.clicked.connect(self.process)
        self.cross_radio.clicked.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Component:')))
        top_layout.addWidget(self.comp_combo)
        top_layout.addWidget(QLabel(self.tr('Projection:')))
        top_layout.addWidget(self.distvect_radio)
        top_layout.addWidget(self.cross_radio)
        top_layout.addStretch()
        bottom_layout = QHBoxLayout()
        bottom_layout.addWidget(table_widget)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.viewer)
        main_layout.addLayout(bottom_layout)
        self.setLayout(main_layout)
Exemple #29
0
    def __init__(self, image, parent=None):
        super(CloningWidget, self).__init__(parent)

        self.detector_combo = QComboBox()
        self.detector_combo.addItems(
            [self.tr('BRISK'),
             self.tr('ORB'),
             self.tr('AKAZE')])
        self.detector_combo.setCurrentIndex(0)
        self.detector_combo.setToolTip(
            self.tr('Algorithm used for localization and description'))
        self.response_spin = QSpinBox()
        self.response_spin.setRange(0, 100)
        self.response_spin.setSuffix(self.tr('%'))
        self.response_spin.setValue(90)
        self.response_spin.setToolTip(
            self.tr('Maximum keypoint response to perform matching'))
        self.matching_spin = QSpinBox()
        self.matching_spin.setRange(1, 100)
        self.matching_spin.setSuffix(self.tr('%'))
        self.matching_spin.setValue(20)
        self.matching_spin.setToolTip(
            self.tr('Maximum metric difference to accept matching'))
        self.distance_spin = QSpinBox()
        self.distance_spin.setRange(1, 100)
        self.distance_spin.setSuffix(self.tr('%'))
        self.distance_spin.setValue(15)
        self.distance_spin.setToolTip(
            self.tr('Maximum distance between matches in the same cluster'))
        self.cluster_spin = QSpinBox()
        self.cluster_spin.setRange(1, 20)
        self.cluster_spin.setValue(5)
        self.cluster_spin.setToolTip(
            self.tr('Minimum number of keypoints to create a new cluster'))
        self.kpts_check = QCheckBox(self.tr('Show keypoints'))
        self.kpts_check.setToolTip(self.tr('Show keypoint coverage'))
        self.nolines_check = QCheckBox(self.tr('Hide lines'))
        self.nolines_check.setToolTip(self.tr('Disable match line drawing'))
        self.process_button = QToolButton()
        self.process_button.setText(self.tr('Process'))
        self.process_button.setToolTip(self.tr('Perform automatic detection'))
        modify_font(self.process_button, bold=True)
        self.status_label = QLabel()
        self.mask_label = QLabel()
        self.mask_button = QToolButton()
        self.mask_button.setText(self.tr('Load mask...'))
        self.mask_button.setToolTip(
            self.tr('Load an image to be used as mask'))
        self.onoff_button = QToolButton()
        self.onoff_button.setText(self.tr('OFF'))
        self.onoff_button.setCheckable(True)
        self.onoff_button.setToolTip(self.tr('Toggle keypoint detection mask'))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
        self.total = self.kpts = self.desc = self.matches = self.clusters = self.mask = None
        self.canceled = False

        self.detector_combo.currentIndexChanged.connect(self.update_detector)
        self.response_spin.valueChanged.connect(self.update_detector)
        self.matching_spin.valueChanged.connect(self.update_matching)
        self.distance_spin.valueChanged.connect(self.update_cluster)
        self.cluster_spin.valueChanged.connect(self.update_cluster)
        self.nolines_check.stateChanged.connect(self.process)
        self.kpts_check.stateChanged.connect(self.process)
        self.process_button.clicked.connect(self.process)
        self.mask_button.clicked.connect(self.load_mask)
        self.onoff_button.toggled.connect(self.toggle_mask)
        self.onoff_button.setEnabled(False)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Detector:')))
        top_layout.addWidget(self.detector_combo)
        top_layout.addWidget(QLabel(self.tr('Response:')))
        top_layout.addWidget(self.response_spin)
        top_layout.addWidget(QLabel(self.tr('Matching:')))
        top_layout.addWidget(self.matching_spin)
        top_layout.addWidget(QLabel(self.tr('Distance:')))
        top_layout.addWidget(self.distance_spin)
        top_layout.addWidget(QLabel(self.tr('Cluster:')))
        top_layout.addWidget(self.cluster_spin)
        top_layout.addWidget(self.nolines_check)
        top_layout.addWidget(self.kpts_check)
        top_layout.addStretch()

        bottom_layout = QHBoxLayout()
        bottom_layout.addWidget(self.process_button)
        bottom_layout.addWidget(self.status_label)
        bottom_layout.addStretch()
        bottom_layout.addWidget(self.mask_button)
        bottom_layout.addWidget(self.onoff_button)

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addLayout(bottom_layout)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)
Exemple #30
0
    def __init__(self, image, parent=None):
        super(CloningWidget, self).__init__(parent)

        self.detector_combo = QComboBox()
        self.detector_combo.addItems(
            [self.tr('BRISK'),
             self.tr('ORB'),
             self.tr('AKAZE')])
        self.detector_combo.setCurrentIndex(0)
        self.detector_combo.setToolTip(
            self.tr('Algorithm used for localization and description'))
        self.response_spin = QSpinBox()
        self.response_spin.setRange(0, 100)
        self.response_spin.setSuffix(self.tr('%'))
        self.response_spin.setValue(90)
        self.response_spin.setToolTip(
            self.tr('Maximum keypoint response to perform matching'))
        self.matching_spin = QSpinBox()
        self.matching_spin.setRange(1, 100)
        self.matching_spin.setSuffix(self.tr('%'))
        self.matching_spin.setValue(20)
        self.matching_spin.setToolTip(
            self.tr('Maximum metric difference to accept matching'))
        self.distance_spin = QSpinBox()
        self.distance_spin.setRange(1, 100)
        self.distance_spin.setSuffix(self.tr('%'))
        self.distance_spin.setValue(15)
        self.distance_spin.setToolTip(
            self.tr('Maximum distance between matches in the same cluster'))
        self.cluster_spin = QSpinBox()
        self.cluster_spin.setRange(1, 20)
        self.cluster_spin.setValue(5)
        self.cluster_spin.setToolTip(
            self.tr('Minimum number of keypoints to create a new cluster'))
        self.nolines_check = QCheckBox(self.tr('Hide lines'))
        self.nolines_check.setToolTip(self.tr('Disable match line drawing'))
        self.process_button = QPushButton(self.tr('Process'))
        self.process_button.setToolTip(self.tr('Perform automatic detection'))
        self.status_label = QLabel(
            self.tr('[Press "Process" button to search for cloned regions]'))

        self.image = image
        self.viewer = ImageViewer(self.image, self.image)
        self.gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
        self.keypoints = self.kpts = self.desc = self.matches = self.clusters = None
        self.canceled = False

        self.detector_combo.currentIndexChanged.connect(self.update_detector)
        self.response_spin.valueChanged.connect(self.update_detector)
        self.matching_spin.valueChanged.connect(self.update_matching)
        self.distance_spin.valueChanged.connect(self.update_cluster)
        self.cluster_spin.valueChanged.connect(self.update_cluster)
        self.nolines_check.stateChanged.connect(self.process)
        self.process_button.clicked.connect(self.process)

        top_layout = QHBoxLayout()
        top_layout.addWidget(QLabel(self.tr('Detector:')))
        top_layout.addWidget(self.detector_combo)
        top_layout.addWidget(QLabel(self.tr('Response:')))
        top_layout.addWidget(self.response_spin)
        top_layout.addWidget(QLabel(self.tr('Matching:')))
        top_layout.addWidget(self.matching_spin)
        top_layout.addWidget(QLabel(self.tr('Distance:')))
        top_layout.addWidget(self.distance_spin)
        top_layout.addWidget(QLabel(self.tr('Cluster:')))
        top_layout.addWidget(self.cluster_spin)
        top_layout.addWidget(self.nolines_check)
        top_layout.addWidget(self.process_button)
        top_layout.addStretch()

        main_layout = QVBoxLayout()
        main_layout.addLayout(top_layout)
        main_layout.addWidget(self.status_label)
        main_layout.addWidget(self.viewer)
        self.setLayout(main_layout)