def save_display_as_image(self, workspace, display, image_name): '''Convert an ImageJ display to an image and save in the image set workspace - current workspace display - an ImageJ Display image_name - save the image in the image set using this name. ''' display_view = display.getActiveView() dataset = ij2.wrap_dataset(display_view.getData()) pixel_data = dataset.get_pixel_data() / IMAGEJ_SCALE mask = ij2.create_mask(display) image = cpi.Image(pixel_data, mask=mask) workspace.image_set.add(image_name, image) return pixel_data
def test_09_08_check_stride(self): # Rotate the image by 90 degrees to make sure the pixel copy # was properly strided # svc = ij2.get_display_service(self.context) i, j = np.mgrid[0:5, 0:70:10] image = i + j ds = ij2.create_dataset(self.context, image, "Foo") display = svc.createDisplay("Foo", ds) outputs = dict(display=None) self.run_command("imagej.core.commands.rotate.Rotate90DegreesLeft", dict(display=display), outputs) display_out = ij2.wrap_display(outputs["display"]) dataset = ij2.wrap_dataset(display_out.getActiveView().getData()) image_out = dataset.get_pixel_data() self.assertSequenceEqual(image_out.shape, list(reversed(image.shape))) np.testing.assert_array_equal(np.rot90(image), image_out)
def test_09_08_check_stride(self): # Rotate the image by 90 degrees to make sure the pixel copy # was properly strided # svc = ij2.get_display_service(self.context) i, j = np.mgrid[0:5, 0:70:10] image = i+j ds = ij2.create_dataset(self.context, image, "Foo") display = svc.createDisplay("Foo", ds) outputs = dict(display=None) self.run_command("imagej.core.commands.rotate.Rotate90DegreesLeft", dict(display=display), outputs) display_out = ij2.wrap_display(outputs["display"]) dataset = ij2.wrap_dataset(display_out.getActiveView().getData()) image_out = dataset.get_pixel_data() self.assertSequenceEqual(image_out.shape, list(reversed(image.shape))) np.testing.assert_array_equal(np.rot90(image), image_out)
def test_09_09_check_overlay(self): svc = ij2.get_display_service(self.context) r = np.random.RandomState() i, j = np.mgrid[0:11, 0:1300:100] image = i+j ds = ij2.create_dataset(self.context, image, "Foo") display = svc.createDisplay("Foo", ds) mask = np.zeros(image.shape, bool) mask[2:-1, 3:-4] = 1 overlay = ij2.create_overlay(self.context, mask) ij2.get_overlay_service(self.context).addOverlays( display.o, J.make_list([overlay])) ij2.select_overlay(display.o, overlay) self.run_command("imagej.core.commands.imglib.CropImage", dict(display=display), {}) dataset = ij2.wrap_dataset(display.getActiveView().getData()) image_out = dataset.get_pixel_data() self.assertSequenceEqual(image_out.shape, [7, 5]) np.testing.assert_array_equal(image[2:-2, 3:-5], image_out)