Ejemplo n.º 1
0
    def test_submatrix(self):
        """crop"""

        tempdir = mkdtemp()

        # crop the test image (size=1388x1040) to be bottom right tile of the test image
        # tiled with 6 cols and 5 rows => ROI= 231x208+1155+832
        orig_big = join(
            pychrm_test_dir,
            'lymphoma_eosin_channel_MCL_test_img_sj-05-3362-R2_001_E.tif')
        orig_cropped = join(
            pychrm_test_dir,
            'lymphoma_eosin_channel_MCL_test_img_sj-05-3362-R2_001_E-t6x5_5_4-l.tiff'
        )
        test_cropped_path = join(tempdir, 'TEST_submatrix.tif')
        x = 1155
        y = 832
        w = 231
        h = 208

        x1 = x
        y1 = y
        x2 = x1 + w - 1
        y2 = y1 + h - 1

        # setting mean = 0 is flag to not use mean in ImageMatrix::OpenImage()
        downsample = 0
        bb = None
        mean = 0.0
        stddev = 0.0
        try:
            origim = PyImageMatrix()
            if 1 != origim.OpenImage(orig_big, downsample, bb, mean, stddev):
                self.fail('Could not build an ImageMatrix from ' + orig_big)

            # API calls for copying desired pixels into empty ImageMatrix instance:
            # the_tiff is garbage collected on return
            cropped_im = PyImageMatrix()
            # void ImageMatrix::submatrix (const ImageMatrix &matrix, const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2)
            cropped_im.submatrix(origim, x1, y1, x2, y2)  # no retval

            cropped_im.SaveTiff(test_cropped_path)

            orig_pixels = plt.imread(orig_cropped)
            cropped_pixels = plt.imread(test_cropped_path)

            assert_equal(orig_pixels, cropped_pixels)

        finally:
            rmtree(tempdir)
Ejemplo n.º 2
0
    def test_submatrix(self):
        """crop"""

        tempdir = mkdtemp()

        # crop the test image (size=1388x1040) to be bottom right tile of the test image
        # tiled with 6 cols and 5 rows => ROI= 231x208+1155+832
        orig_big = join(
            pychrm_test_dir,
            'lymphoma_eosin_channel_MCL_test_img_sj-05-3362-R2_001_E.tif')
        orig_cropped = join(
            pychrm_test_dir,
            'lymphoma_eosin_channel_MCL_test_img_sj-05-3362-R2_001_E-t6x5_5_4-l.tiff'
        )
        test_cropped_path = join(tempdir, 'TEST_submatrix.tif')
        x = 1155
        y = 832
        w = 231
        h = 208

        x1 = x
        y1 = y
        x2 = x1 + w - 1
        y2 = y1 + h - 1

        # setting mean = 0 is flag to not use mean in ImageMatrix::OpenImage()
        downsample = 0
        bb = None
        mean = 0.0
        stddev = 0.0
        try:
            origim = PyImageMatrix()
            if 1 != origim.OpenImage(orig_big, downsample, bb, mean, stddev):
                self.fail('Could not build an ImageMatrix from ' + orig_big)

            # API calls for copying desired pixels into empty ImageMatrix instance:
            # the_tiff is garbage collected on return
            cropped_im = PyImageMatrix()
            # void ImageMatrix::submatrix (const ImageMatrix &matrix, const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2)
            cropped_im.submatrix(origim, x1, y1, x2, y2)  # no retval

            cropped_im.SaveTiff(test_cropped_path)

            orig_pixels = plt.imread(orig_cropped)
            cropped_pixels = plt.imread(test_cropped_path)

            assert_equal(orig_pixels, cropped_pixels)

        finally:
            rmtree(tempdir)