예제 #1
0
 def compare_image_pixels(self, result_image, correct_result_image, threshold):
     self.fail_test_if_no_oiio()
     """ 
     Given a file to find it results, compare it against the correct result. 
     Returns None if the input is not an image. 
     Returns oiio.CompareResults if results can be compared. 
     """
     compresults = oiio.CompareResults()
     ImageBufAlgo.compare(result_image, correct_result_image, threshold, threshold, compresults)
     return compresults
예제 #2
0
    write(b, "unpremult.tif")
    ImageBufAlgo.premult(b, b)
    write(b, "premult.tif")

    b = ImageBuf("../oiiotool/tahoe-small.tif")
    ImageBufAlgo.rangecompress(b, b)
    write(b, "rangecompress.tif", oiio.UINT8)
    ImageBufAlgo.rangeexpand(b, b)
    write(b, "rangeexpand.tif", oiio.UINT8)

    # FIXME - colorconvert, ociolook need tests

    # computePixelStats

    compresults = oiio.CompareResults()
    ImageBufAlgo.compare(ImageBuf("flip.tif"), ImageBuf("flop.tif"), 1.0e-6, 1.0e-6, compresults)
    print "Comparison: of flip.tif and flop.tif"
    print "  mean =", compresults.meanerror
    print "  rms  =", compresults.rms_error
    print "  PSNR =", compresults.PSNR
    print "  max  =", compresults.maxerror
    print "  max @", (compresults.maxx, compresults.maxy, compresults.maxz, compresults.maxc)
    print "  warns", compresults.nwarn, "fails", compresults.nfail

    # compare_Yee,
    # isConstantColor, isConstantChannel

    b = ImageBuf(ImageSpec(256, 256, 3, oiio.UINT8))
    ImageBufAlgo.fill(b, (1, 0.5, 0.5))
    r = ImageBufAlgo.isConstantColor(b)
    print "isConstantColor on pink image is", r
예제 #3
0
    write(b, "unpremult.tif")
    ImageBufAlgo.premult(b, b)
    write(b, "premult.tif")

    b = ImageBuf("../oiiotool/tahoe-small.tif")
    ImageBufAlgo.rangecompress(b, b)
    write(b, "rangecompress.tif", oiio.UINT8)
    ImageBufAlgo.rangeexpand(b, b)
    write(b, "rangeexpand.tif", oiio.UINT8)

    # FIXME - colorconvert, ociolook need tests

    # computePixelStats

    compresults = oiio.CompareResults()
    ImageBufAlgo.compare(ImageBuf("flip.tif"), ImageBuf("flop.tif"), 1.0e-6,
                         1.0e-6, compresults)
    print "Comparison: of flip.tif and flop.tif"
    print "  mean =", compresults.meanerror
    print "  rms  =", compresults.rms_error
    print "  PSNR =", compresults.PSNR
    print "  max  =", compresults.maxerror
    print "  max @", (compresults.maxx, compresults.maxy, compresults.maxz,
                      compresults.maxc)
    print "  warns", compresults.nwarn, "fails", compresults.nfail

    # compare_Yee,
    # isConstantColor, isConstantChannel

    b = ImageBuf(ImageSpec(256, 256, 3, oiio.UINT8))
    ImageBufAlgo.fill(b, (1, 0.5, 0.5))
    r = ImageBufAlgo.isConstantColor(b)
예제 #4
0
    def compare(self, diff_image_location=None, blur=10, raise_exception=True):
        """Compare the two given images

        Args:
            diff_image_location (str): file path for difference image.
                Written only if there are failures
            blur (float): image blur to apply before comparing
        """

        if not diff_image_location:
            diff_image_location = os.path.dirname(self._image_a_location)

        self.blur_images(blur)
        ImageBufAlgo.compare(
            self.image_a_buffer,
            self.image_b_buffer,
            self.fail_threshold,
            self.warn_threshold,
            self._compare_results,
        )
        diff_buffer = self.create_diff_buffer()

        if self.debug:
            self.image_a_buffer.write(
                '{}/{}_debug{}'.format(
                    diff_image_location,
                    os.path.basename(self._image_a_location),
                    self._file_ext,
                )
            )
            self.image_b_buffer.write(
                '{}/{}_debug{}'.format(
                    diff_image_location,
                    os.path.basename(self._image_b_location),
                    self._file_ext,
                )
            )

        if self._compare_results.nfail > 0:
            ImageBufAlgo.color_map(diff_buffer, diff_buffer, -1, 'inferno')
            remap_buffer = ImageBuf()
            multiplier = 5
            ImageBufAlgo.mul(
                remap_buffer,
                diff_buffer,
                (multiplier, multiplier, multiplier, 1.0),
            )
            ImageBufAlgo.add(remap_buffer, self.image_a_buffer, remap_buffer)
            msg = report_msg.format(
                failures=self._compare_results.nfail,
                warn=self._compare_results.nwarn,
                meanerror=self._compare_results.meanerror,
                rmserror=self._compare_results.rms_error,
                psnr=self._compare_results.PSNR
            )

            remap_buffer.write(
                '{}/{}-{}_diff{}'.format(
                    diff_image_location,
                    os.path.basename(self._image_a_location),
                    os.path.basename(self._image_b_location),
                    self._file_ext,
                )
            )
            self.image_a_buffer.write(
                '{}/{}_debug{}'.format(
                    diff_image_location,
                    '1_a',
                    self._file_ext,
                )
            )
            self.image_b_buffer.write(
                '{}/{}_debug{}'.format(
                    diff_image_location,
                    '1_b',
                    self._file_ext,
                )
            )
            if raise_exception:
                raise ImageDifferenceError(msg)
            else:
                print(msg)