def it_calculate_resampled_nparray_from_small_region_svs_image(self): slide = Slide(SVS.CMU_1_SMALL_REGION, os.path.join(SVS.CMU_1_SMALL_REGION, "processed")) resampled_array = slide.resampled_array(scale_factor=32) expected_value = load_expectation( "svs-images/small-region-svs-resampled-array", type_="npy") np.testing.assert_almost_equal(resampled_array, expected_value)
def it_knows_its_resampled_array(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) resampled_array = slide.resampled_array(scale_factor=32) assert type(resampled_array) == np.ndarray assert resampled_array.shape == (400, 300, 3)
# Inside the save_thumbnail pil_img = pdx_slide._wsi.get_thumbnail(pdx_slide._thumbnail_size) print(type(pil_img)) print(pil_img.size) # pil_img.show() # why this doesn't work?? # plt.imshow(pil_img); plt.axis('off'); pil_img.save(tmp_outpath / 'pil_img.png', format='png') # Apply mask to image pil_img_boxed = histolab.util.apply_mask_image( pil_img, pdx_slide.biggest_tissue_box_mask) pil_img_boxed.save(tmp_outpath / 'pil_img_boxed.png', format='png') # Scale and save image scale_factor = 16 np_img_scaled = pdx_slide.resampled_array( scale_factor=scale_factor) # scale and return ndarray print(type(np_img_scaled)) print(np_img_scaled.shape) # out image file path: {name}-{scale_factor}x-{large_w}x{large_h}-{new_w}x{new_h}.{IMG_EXT} pdx_slide.save_scaled_image( scale_factor=scale_factor) # scale and save into file # Show img from array # plt.imshow(img_scaled); plt.axis('off'); fig, ax = plt.subplots(figsize=(5, 5)) ax.imshow(np_img_scaled) ax.axis('off') # PIL.Image.fromarray(np_img_scaled) # ----------------------------------- # Metadata