0

I can't find the true approach in order to invert the result image. I tried to use inverse=True argument inside pygame.transform.threshold method but it results in errors. In other words, I need to take inverse threshold.

def threshold_image(self, image):

    """Applies a threshold to an image and returns the thresholded image

    arguments
    image           --  the image that should be thresholded, a
                        pygame.surface.Surface instance

    returns
    thresholded     --  the thresholded image, a
                        pygame.surface.Surface instance
    """

    # surface to apply threshold to surface
    thimg = pygame.surface.Surface(self.get_size(), 0, image)

    # perform thresholding
    th = (self.settings['threshold'], self.settings['threshold'],
          self.settings['threshold'])
    pygame.transform.threshold(thimg, image, self.settings['pupilcol'], th,
                               self.settings['nonthresholdcol'], 1)

    return thimg
General Grievance
  • 4,555
  • 31
  • 31
  • 45
oğul can
  • 3
  • 1

1 Answers1

0

I'm not sure but something like the following with the added line right be before the return thimg statement should invert the results you're getting the way you want:

-- Untested --

def threshold_image(self, image):

    """Applies a threshold to an image and returns the thresholded image

    arguments
    image           --  the image that should be thresholded, a
                        pygame.surface.Surface instance

    returns
    thresholded     --  the thresholded image, a
                        pygame.surface.Surface instance
    """

    # surface to apply threshold to surface
    thimg = pygame.surface.Surface(self.get_size(), 0, image)

    # perform thresholding
    th = (self.settings['threshold'], self.settings['threshold'],
          self.settings['threshold'])
    pygame.transform.threshold(thimg, image, self.settings['pupilcol'], th,
                               self.settings['nonthresholdcol'], 1)

    # Additional statements to invert results
    inv = pygame.Surface(thimg.get_rect().size)
    inv.fill((255,255,255))
    inv.blit(thimg, (0,0), None, pygame.BLEND_RGB_SUB)

    return thimg
martineau
  • 119,623
  • 25
  • 170
  • 301