def it_can_resample_itself(self, tmpdir, resampled_dims_): tmp_path_ = tmpdir.mkdir("myslide") image = PILIMG.RGBA_COLOR_500X500_155_249_240 image.save(os.path.join(tmp_path_, "mywsi.png"), "PNG") slide_path = os.path.join(tmp_path_, "mywsi.png") slide = Slide(slide_path, "processed") resampled_dims_.return_value = (100, 200, 300, 400) _resample = slide._resample(32) # image array assertions assert type(_resample[1]) == np.ndarray # ---The np array shape should be (new_h X new_w X channels),--- # ---in this case (look at resampled_dims mock) the new_h is 400--- # ---the new_w is 300 and the color channels of the image are 3--- assert _resample[1].shape == (400, 300, 3) # ---Here we prove that the 3 channels are compliant with the color--- # ---definition and that each channel is a np.array (400x300) filled--- # ---with the related color expressed during the image creation--- np.testing.assert_almost_equal(_resample[1][:, :, 0], np.full((400, 300), 155)) np.testing.assert_almost_equal(_resample[1][:, :, 1], np.full((400, 300), 249)) np.testing.assert_almost_equal(_resample[1][:, :, 2], np.full((400, 300), 240)) # PIL image assertions assert type(_resample[0]) == PIL.Image.Image assert _resample[0].size == (300, 400) assert _resample[0].width == 300 assert _resample[0].height == 400 assert _resample[0].mode == "RGB"
def it_resamples_with_the_correct_scale_factor(self, tmpdir, resampled_dims_): tmp_path_ = tmpdir.mkdir("myslide") image = PILIMG.RGBA_COLOR_500X500_155_249_240 image.save(os.path.join(tmp_path_, "mywsi.png"), "PNG") slide_path = os.path.join(tmp_path_, "mywsi.png") slide = Slide(slide_path, "processed") resampled_dims_.return_value = (500, 500, 15, 15) _resample = slide._resample(32) assert _resample[1].shape == (math.floor(500 / 32), math.floor(500 / 32), 3)