Esempio n. 1
0
    def __init__(self, image: ImageWrapper):
        super().__init__()
        self.image = image
        image.draw_image()

        qim = ImageQt(image.image_element)
        # self.drawn_image = QPixmap(self.image.file_path)
        # self.drawn_image = QPixmap.fromImage(qim)
        """channels = image.image_element.split()
        for channel in channels:
            op.channel_penderated_median_window_3x3(channel)
            # x = channel_histogram(channel, True)"""

        #pil_img = Image.merge(image.image_element.mode, channels)

        #self.drawn_image = self.pil2pixmap(pil_img)
        self.drawn_image = self.pil2pixmap(image.image_element)

        self.selection_start = None
        self.selection_end = None

        self.drawing = False
        self.lastPoint = QPoint()

        self.curr_pointer = None

        self.handler_selection_finished = None

        self.init_ui()
Esempio n. 2
0
def apply_susan_border_detection(t: int, image: ImageWrapper, s_border: float,
                                 s_corner: float) -> ImageWrapper:
    channel = image.channels[0]

    channels = [channel.copy(), channel.copy(), channel.copy()]

    borders = susan_border_detection(t, channel, s_border, s_corner)

    w, h = channel.shape

    for x in range(w):
        for y in range(h):
            if borders[x, y] == Detection.corner:
                channels[0][x, y] = 0
                channels[1][x, y] = 255
                channels[2][x, y] = 0
            elif borders[x, y] == Detection.border:
                channels[0][x, y] = 0
                channels[1][x, y] = 0
                channels[2][x, y] = 255
            else:
                channels[0][x, y] = channel[x, y]
                channels[1][x, y] = channel[x, y]
                channels[2][x, y] = channel[x, y]

    image.channels = channels
    image.mode = 'RGB'

    return image
Esempio n. 3
0
 def handler(paths, dimensions=None):
     if dimensions is None:
         dimensions = [None, None]
     self.first_image = ImageWrapper.from_path(paths[0])
     self.second_image = ImageWrapper.from_path(paths[1])
     self.set_enabled_operations(True)
     self.select_images_btn.setEnabled(False)
Esempio n. 4
0
def pixel_transformation(image: ImageWrapper, transformation_function):
    w, h = image.dimensions()

    matrix = []

    for x in range(w):
        row = []
        for y in range(h):
            val = transformation_function(x, y, image.get_pixel(x, y))

            row.append(tuple(val))
        matrix.append(row)

    return matrix_to_image(normalized_matrix(matrix), mode=image.get_mode())
Esempio n. 5
0
def scalar_multiplication(first_image: ImageWrapper, scalar: float):
    w, h = first_image.dimensions()

    result = ImageWrapper.from_dimensions(w, h, mode=first_image.get_mode())

    for x in range(w):
        for y in range(h):
            val = [
                int(first_image.get_pixel(x, y)[i] * scalar) % 255
                for i in range(len(first_image.get_pixel(x, y)))
            ]
            result.set_pixel(x, y, tuple(val))

    return result
Esempio n. 6
0
def rayleigh_multiplicative_noise(image: ImageWrapper, gamma,
                                  percentage: float):
    w, h = image.dimensions()
    fn = noise_percentage(
        multiplicative_noise(lambda: np.random.rayleigh(scale=gamma)),
        percentage, w, h)
    return pixel_transformation(image, fn)
Esempio n. 7
0
def exponential_multiplicative_noise(image: ImageWrapper, _lambda,
                                     percentage: float):
    w, h = image.dimensions()
    fn = noise_percentage(
        multiplicative_noise(lambda: np.random.exponential(scale=1 / _lambda)),
        percentage, w, h)
    return pixel_transformation(image, fn)
Esempio n. 8
0
def equalize_histogram(image: ImageWrapper):
    channels = image.get_image_element().split()
    eq_channel_mappings = []

    for channel in channels:
        channel_hist = channel_histogram(channel, display=True)

        eq_channel_mapping_buffer = [0] * len(channel_hist)
        for k in range(len(channel_hist)):
            for j in range(k):
                eq_channel_mapping_buffer[k] += channel_hist[j]

        eq_channel_mapping = []
        s_min = min(eq_channel_mapping_buffer)
        for k in range(len(channel_hist)):
            eq_channel_mapping.append(
                round(255 * ((eq_channel_mapping_buffer[k] - s_min) /
                             (1 - s_min))))

        eq_channel_mappings.append(eq_channel_mapping)

    def mapping_function(x, y, value):
        return [eq_channel_mappings[i][value[i]] for i in range(len(value))]

    result = pixel_transformation(image, mapping_function)

    for channel in result.image_element.split():
        channel_histogram(channel, display=True)

    return result
Esempio n. 9
0
def gaussian_additive_noise(image: ImageWrapper, mu: float, sigma: float,
                            percentage: float):
    w, h = image.dimensions()
    fn = noise_percentage(
        additive_noise(lambda: np.random.normal(loc=mu, scale=sigma)),
        percentage, w, h)
    return pixel_transformation(image, fn)
Esempio n. 10
0
def matrix_to_image(matrix: List[List[tuple]], mode=None) -> ImageWrapper:
    w: int = len(matrix)
    h: int = len(matrix[0])
    result: ImageWrapper = ImageWrapper.from_dimensions(w, h, mode)
    for x in range(w):
        for y in range(h):
            result.set_pixel(x, y, tuple([int(a) for a in matrix[x][y]]))
    return result
Esempio n. 11
0
    def selectFileButton_clicked(self):
        options = QFileDialog.Options()
        filePath, _ = QFileDialog.getOpenFileName(self, "Select image file", "",
                                                  "Images (*.jpg *.jpeg *.raw *.ppm *.pgm *.RAW *.png)",
                                                  options=options)
        if filePath:
            self.loadedImage_changed(ImageWrapper.from_path(filePath))
            return True

        return False
Esempio n. 12
0
    def selectMultipleFilesButton_clicked(self):
        options = QFileDialog.Options(QFileDialog.ExistingFiles)
        filePaths, _ = QFileDialog.getOpenFileNames(self, "Select image files", "",
                                                    "Images (*.jpg *.jpeg *.raw *.ppm *.pgm *.RAW *.png)",
                                                    options=options)

        filePaths.sort()

        self.images_paths = filePaths

        new_image_window = ImageSectionSelectorWindow(ImageWrapper.from_path(filePaths[0]), self.prueba_callback,
                                                      "Select section")
        self.imageVisualizerWindows.append(new_image_window)
        new_image_window.show()
Esempio n. 13
0
    def run(self):
        point_a, point_b = self.points

        dim = (point_b[0] - point_a[0], point_b[1] - point_a[1])

        border_tracking = BorderTracking(point_a, dim, self.epsilon)

        for i, img_path in enumerate(self.images_paths):
            startTime = time.time()
            result = border_tracking.next_image(ImageWrapper.from_path(img_path))
            result.draw_image()
            self.add_image_to_carrousel_signal.emit(result,
                                                    f"<b>Frame {i + 1}/{len(self.images_paths)}</b> (Time spent: {round(time.time() - startTime, 2)}s)")
            self.update_progressbar_signal.emit((i + 1) / len(self.images_paths) * 100)
Esempio n. 14
0
def salt_and_pepper(image: ImageWrapper, p0: float, p1: float,
                    percentage: float):
    def noise(x, y, val):
        res = []

        for v in val:
            rnd: float = np.random.uniform(0, 1)

            if rnd < p0:
                res.append(0)
            elif rnd > p1:
                res.append(255)
            else:
                res.append(v)

        return res

    w, h = image.dimensions()
    fn = noise_percentage(noise, percentage, w, h)
    return pixel_transformation(image, fn)
Esempio n. 15
0
def pixel_to_pixel_operation(first_image: ImageWrapper,
                             second_image: ImageWrapper, operation):
    assert first_image.dimensions() == second_image.dimensions()

    w, h = first_image.dimensions()
    matrix = []

    for x in range(w):
        row = []
        for y in range(h):
            val = [
                operation(
                    first_image.get_pixel(x, y)[i],
                    second_image.get_pixel(x, y)[i])
                for i in range(len(first_image.get_pixel(x, y)))
            ]
            row.append(tuple(val))
        matrix.append(row)

    return matrix_to_image(normalized_matrix(matrix),
                           mode=first_image.get_mode())
Esempio n. 16
0
File: noise.py Progetto: Fastiz/ATI
def apply_salt_and_pepper(image, parameter):
    result = salt_and_pepper(ImageWrapper(Image.fromarray(image)), parameter, 1 - parameter, 1).draw_image()
    return np.array(result)
Esempio n. 17
0
 def reload_from_disk_clicked(self):
     self.loadedImage_changed(ImageWrapper.from_path(self.image.file_path))