-
Notifications
You must be signed in to change notification settings - Fork 1
Add ColorBlending module for multi-image blending support #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
6087d69
d6961b2
9fa89de
85b3528
06445bc
266f1c1
606c9f3
8e560b9
34bf41b
5d4fca4
032949d
2e0abce
5c52466
06fff60
b7af8dc
fbcf72f
6596ab3
9a20cfa
d9bcab4
a34e646
4ce4429
25e0baa
cb22ed5
91e952d
3f1c4fe
d337759
345c17d
2bf9d1f
e16c9f4
2812ffa
509d4e2
af48cf3
2f7d76b
56e019d
6e02ba2
9ea1a66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,8 +171,9 @@ Helper methods on the session object open images in the frontend and return imag | |
| .. code-block:: python | ||
|
|
||
| # Open or append images | ||
| img1 = session.open_image("data/hdf5/first_file.hdf5") | ||
| img2 = session.open_image("data/fits/second_file.fits", append=True) | ||
| img0 = session.open_image("data/hdf5/first_file.hdf5") | ||
| img1 = session.open_image("data/fits/second_file.fits", append=True) | ||
| img2 = session.open_image("data/fits/third_file.fits", append=True) | ||
|
|
||
| Changing image properties | ||
| ------------------------- | ||
|
|
@@ -192,7 +193,7 @@ Properties specific to individual images can be accessed through image objects: | |
| # pan and zoom | ||
| y, x = img.shape[-2:] | ||
| img.set_center(x/2, y/2) | ||
| img.set_zoom(4) | ||
| img.set_zoom_level(4) | ||
|
|
||
| # change colormap | ||
| img.raster.set_colormap(Colormap.VIRIDIS) | ||
|
|
@@ -225,7 +226,117 @@ Properties which affect the whole session can be set through the session object: | |
| session.wcs.global_.set_color(PaletteColor.RED) | ||
| session.wcs.ticks.set_color(PaletteColor.VIOLET) | ||
| session.wcs.title.show() | ||
|
|
||
|
|
||
| Making color blended image | ||
| -------------------------- | ||
|
|
||
| Create a color blending object from a list of files: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from carta.colorblending import ColorBlending | ||
| from carta.constants import Colormap, ColormapSet | ||
|
|
||
| # Make a color blending object | ||
| # Warning: setting `append=False` will close any existing images | ||
| # Note: The base layer (index = 0) cannot be deleted or moved. | ||
| files = [ | ||
| "data/hdf5/first_file.hdf5", | ||
| "data/fits/second_file.fits", | ||
| "data/fits/third_file.fits", | ||
| ] | ||
| cb = ColorBlending.from_files(session, files, append=False) | ||
|
|
||
| Create a color blending object from a list of images: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from carta.colorblending import ColorBlending | ||
| from carta.constants import Colormap, ColormapSet | ||
|
|
||
| # Make a color blending object | ||
| # Warning: This will break the current spatial matching and | ||
| # use the first image as the spatial reference | ||
| # Note: The base layer (index = 0) cannot be deleted or moved. | ||
| cb = ColorBlending.from_images(session, [img0, img1, img2]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this should not be exposed. I'm not sure if it would be best to add the wrapper method to the session object (e.g. maybe |
||
|
|
||
| To work with color blending images that are already open in a session, use | ||
| the session helper: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # Get all open color blending objects in this session | ||
| color_blendings = session.color_blending_list() | ||
| cb = color_blendings[0] | ||
|
|
||
| # Or get a color blending object by its image view index | ||
| cb = ColorBlending.from_imageview_id(session, 3) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also not be exposed. Is each colour blending also an image that appears in the image list? If yes, then the wrapper for this should be on the image object, and be decorated as an attribute, since the only parameter is the image's ID. Then the user could access it with Broader question: if each color blending is also an image and can be accessed through an image object in the wrapper, does that break anything (because it's not a normal image)? E.g. what will happen if the user accesses a blending as an image object and tries to get the number of channels? If this does break image functionality, I think that the correct thing to do is to specialise |
||
|
|
||
| .. note:: | ||
| The ``ColorBlending`` constructor takes the internal color blending store ID, | ||
| not the image view index. Use ``ColorBlending.from_files``, | ||
| ``ColorBlending.from_images``, ``ColorBlending.from_imageview_id`` or | ||
| ``session.color_blending_list`` in scripts. | ||
|
|
||
| Manipulate properties of the color blending object and the underlying images: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # Get layer objects | ||
| layers = cb.layer_list() | ||
|
|
||
| # Set colormap for individual layers | ||
| layers[0].set_colormap(Colormap.REDS) | ||
| layers[1].set_colormap(Colormap.GREENS) | ||
| layers[2].set_colormap(Colormap.BLUES) | ||
|
Comment on lines
+285
to
+291
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest unpacking in the assignment, like this: |
||
|
|
||
| # Or apply an existing colormap set | ||
| cb.set_colormap_set(ColormapSet.RGB) | ||
|
|
||
| # Print the current alpha values of all layers | ||
| print(cb.alpha) | ||
|
|
||
| # Set alpha for individual layers | ||
| layers[0].set_alpha(0.7) | ||
| layers[1].set_alpha(0.8) | ||
| layers[2].set_alpha(0.9) | ||
|
|
||
| # Or set alpha for all layers at once | ||
| cb.set_alpha([0.7, 0.8, 0.9]) | ||
|
|
||
| # Set which layers to keep, and in what order | ||
| # The first layer index must be the base layer (index = 0) | ||
| # Since the base layer cannot be moved, | ||
| # the layers will be reordered as [img0, img2, img1] | ||
| cb.set_layer_sequence([0, 2, 1]) | ||
|
|
||
| # Remove the last layer (index = 2) | ||
| cb.delete_layer(2) | ||
|
|
||
| # Add a new layer | ||
| # The layer to be added cannot be one of the current layers | ||
| cb.add_layer(img1) | ||
|
|
||
| # Set center | ||
| cb.set_center(100, 100) | ||
|
|
||
| # Set zoom level | ||
| cb.set_zoom_level(2) | ||
|
|
||
| # Set the color blending object as the active frame | ||
| cb.make_active() | ||
|
|
||
| # Set contour visibility | ||
| # This will hide the contours (if any) | ||
| cb.set_contour_visible(False) | ||
|
|
||
| # Close the color blending object | ||
| cb.close() | ||
|
|
||
| .. note:: | ||
| If you need to change the layer order involving the base layer (index = 0), | ||
| close the current color blending object and create a new one. | ||
|
|
||
| Saving or displaying an image | ||
| ----------------------------- | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class method should not be exposed to the user directly. The user should access it through a wrapper on the session object, e.g. something like
session.open_as_color_blending([path1, path2, path3]).This is analogous to the
open_imagesfunction on the session.