def get_cropped_index(self): if self.crop_index is None: nu, self.crop_index = nputils.crop_threshold( self.get_mask(), output_index=True) return self.crop_index
def test_region_image(): m2 = np.zeros([5, 5]) m2[2:3, 2:4] = 1 img1 = imgutils.gaussian(100, width=6, angle=-0.5, center=[70, 55]) img1[img1 < 0.1] = 0 seg1, index = nputils.crop_threshold(img1, output_index=True) region1 = imgutils.ImageRegion(img1, index) assert np.allclose(region1.get_region(), seg1) assert np.allclose(region1.get_data(), img1) assert region1.get_shape() == img1.shape assert region1.get_shift() == [0, 0] assert region1.get_index() == index assert list(region1.get_center()) == [70, 55] region1.set_shift([-5, -4]) img2 = imgutils.gaussian(100, width=6, angle=-0.5, center=[65, 51]) img2[img2 < 0.1] = 0 seg2, index2 = nputils.crop_threshold(img2, output_index=True) assert np.allclose(region1.get_region(), seg2) assert np.allclose(region1.get_data(), img2) assert list(region1.get_center()) == [65, 51], region1.get_center() region1.set_shift([-70, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[0, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [0 + 6 / 2, 65] region1.set_shift([30, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[100, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [100 - 5 / 2, 65], (region1.get_center(), seg3.shape) region1.set_shift([20, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[90, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [90, 65] region2 = imgutils.ImageRegion(img2, index2) builder = imgutils.ImageBuilder() builder.add(region1) builder.add(region2) res = builder.get() seg4, index = nputils.crop_threshold(img2 + img3, output_index=True) assert res.get_shape() == img1.shape assert np.allclose(res.get_data(), img3 + img2) assert np.allclose(res.get_region(), seg4) assert res.get_index() == index
def test_region_image(): m2 = np.zeros([5, 5]) m2[2:3, 2:4] = 1 img1 = imgutils.gaussian(100, width=6, angle=-0.5, center=[70, 55]) img1[img1 < 0.1] = 0 seg1, index = nputils.crop_threshold(img1, output_index=True) region1 = imgutils.ImageRegion(img1, index) assert np.allclose(region1.get_region(), seg1) assert np.allclose(region1.get_data(), img1) assert region1.get_shape() == img1.shape assert region1.get_shift() == [0, 0] assert region1.get_index() == index assert list(region1.get_center()) == [70, 55] region1.set_shift([-5, -4]) img2 = imgutils.gaussian(100, width=6, angle=-0.5, center=[65, 51]) img2[img2 < 0.1] = 0 seg2, index2 = nputils.crop_threshold(img2, output_index=True) assert np.allclose(region1.get_region(), seg2) assert np.allclose(region1.get_data(), img2) assert list(region1.get_center()) == [65, 51], region1.get_center() region1.set_shift([-70, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[0, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [0 + 6 / 2, 65] region1.set_shift([30, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[100, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [100 - 5 / 2, 65 ], (region1.get_center(), seg3.shape) region1.set_shift([20, 10]) img3 = imgutils.gaussian(100, width=6, angle=-0.5, center=[90, 65]) img3[img3 < 0.1] = 0 seg3, index = nputils.crop_threshold(img3, output_index=True) assert np.allclose(region1.get_region(), seg3) assert np.allclose(region1.get_data(), img3) assert list(region1.get_center()) == [90, 65] region2 = imgutils.ImageRegion(img2, index2) builder = imgutils.ImageBuilder() builder.add(region1) builder.add(region2) res = builder.get() seg4, index = nputils.crop_threshold(img2 + img3, output_index=True) assert res.get_shape() == img1.shape assert np.allclose(res.get_data(), img3 + img2) assert np.allclose(res.get_region(), seg4) assert res.get_index() == index
def get_cropped_index(self): if self.crop_index is None: nu, self.crop_index = nputils.crop_threshold(self.get_mask(), output_index=True) return self.crop_index