Skip to content
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

A way to programmatically set opacity and color of layers? #827

Closed
azatian opened this issue Nov 28, 2022 · 11 comments
Closed

A way to programmatically set opacity and color of layers? #827

azatian opened this issue Nov 28, 2022 · 11 comments
Assignees
Labels

Comments

@azatian
Copy link

azatian commented Nov 28, 2022

Hello!

Is there a way to programmatically set the opacity and the color of layers? Is there a value I can programmatically set within the meta data json file that would enable this automatically? Please see screenshot below. The default settings for these two layers is that there is 100 opacity and no color set.

Thank you for your help.

Screen Shot 2022-11-28 at 2 14 41 PM

@hotzenklotz
Copy link
Member

Yes, you can specify the default values for each layer programmatically. You set dataset.default_view_configuration = LayerViewConfiguration(...). This code snippet contains an example.

For completeness sake, here is how you set this manually.

Keep in mind, the first time you open any dataset and fiddle with these values, webKnossos will save your personal preference. In other words, changing the default values will only go into effect for 1) users opening a dataset for the first time or 2) new datasets.

@azatian
Copy link
Author

azatian commented Nov 28, 2022 via email

@hotzenklotz
Copy link
Member

Is it possible to do this with wkcuber?

No, it is not possible with the wKCuber. You can, however, you use the wK Python Lib to convert a TIFF image stack with Dataset.from_images(...). This is used by the wkCuber under the hood anyway.

@azatian
Copy link
Author

azatian commented Nov 29, 2022

Thank you! I have been making some progress on this with the WK Python Lib
Each individual TIFF file has a shape of 160x160x16, but when I add the TIFFs as layers, the width comes out to be 160, the height comes out to be 16, and the depth comes out to be 1. Is there something that I am missing here?

 dataset = wk.Dataset("cutouts/dcvsyn1", voxel_size=(4,4,40))

 img_layer = dataset.add_layer_from_images(images="cutouts/dcvsyn1_source",
                                 layer_name="img", dtype='uint8', channel=0)

 pre_layer = dataset.add_layer_from_images(images="cutouts/dcvsyn1_presyn",
                                             layer_name="presyn", dtype='uint8', channel=0)

 post_layer = dataset.add_layer_from_images(images="cutouts/dcvsyn1_postsyn",
                                             layer_name="postsyn", dtype='uint8', channel=0)

 pre_layer.default_view_configuration = LayerViewConfiguration(
         color=(184, 66, 66), alpha=20)

 post_layer.default_view_configuration = LayerViewConfiguration(
         color=(57, 81, 137), alpha=20)

@azatian
Copy link
Author

azatian commented Nov 30, 2022

I think I've somewhat figured out what might the issue be. Dataset.from_images reads the single but multi-page TIFF file differently from add_layer_from_images. Might have to do with Dataset.ConversionLayerMapping? See corresponding json file below.

dataset = wk.Dataset.from_images(input_path="cutouts/dcvsyn1_source",
                                output_path="cutouts/dcvsyn1",
                                voxel_size=(4,4,40),
                                name="dcvsyn1")
   
dataset.layers['vol.tiff'].name = "img"
    
pre_layer = dataset.add_layer_from_images(images="cutouts/dcvsyn1_presyn",
                                               layer_name="presyn", dtype='uint8', channel=1)
{
    "id": {
        "name": "dcvsyn1",
        "team": ""
    },
    "scale": [
        4.0,
        4.0,
        40.0
    ],
    "dataLayers": [
        {
            "name": "img",
            "category": "color",
            "boundingBox": {
                "topLeft": [
                    0,
                    0,
                    0
                ],
                "width": 160,
                "height": 160,
                "depth": 16
            },
            "elementClass": "uint8",
            "dataFormat": "wkw",
            "numChannels": 1,
            "wkwResolutions": [
                {
                    "cubeLength": 1024,
                    "resolution": [
                        1,
                        1,
                        1
                    ]
                }
            ]
        },
        {
            "name": "presyn",
            "category": "color",
            "boundingBox": {
                "topLeft": [
                    0,
                    0,
                    0
                ],
                "width": 160,
                "height": 16,
                "depth": 1
            },
            "elementClass": "uint8",
            "dataFormat": "wkw",
            "numChannels": 1,
            "wkwResolutions": [
                {
                    "cubeLength": 1024,
                    "resolution": [
                        1,
                        1,
                        1
                    ]
                }
            ]
        }
    ]
}

@jstriebel
Copy link
Contributor

@azatian Thank you for reporting this bug! 🐞

I think I can reproduce the problem locally and will work on a fix. In the meantime it might work for you if you use the full path to the file in add_layer_from_images:

dataset.add_layer_from_images(images="cutouts/dcvsyn1_presyn/name_of_your.tiff", …)

I'll write back when the fix is deployed, then it should work with the folder-name as well.

@jstriebel jstriebel self-assigned this Nov 30, 2022
@jstriebel jstriebel added bug and removed enhancement labels Nov 30, 2022
@azatian
Copy link
Author

azatian commented Nov 30, 2022

Hello! I see! I shall try that. I was able to get around it by doing making individual datasets per layer but tying them with the same output path:

dataset = wk.Dataset.from_images(input_path="cutouts/dcvsyn1_source",
                                output_path="cutouts/dcvsyn1",
                                voxel_size=(4,4,40),
                                name="dcvsyn1")

dataset.layers['vol.tiff'].name = "img"
dataset_pre = wk.Dataset.from_images(input_path="cutouts/dcvsyn1_presyn",
                                output_path="cutouts/dcvsyn1",
                                voxel_size=(4,4,40),
                                name="dcvsyn1")
    

dataset_pre.layers['presyn.tiff'].default_view_configuration = LayerViewConfiguration(color=(184, 66, 66), alpha=20)
dataset_pre.layers['presyn.tiff'].name = "presyn"

dataset_post = wk.Dataset.from_images(input_path="cutouts/dcvsyn1_postsyn",
                                output_path="cutouts/dcvsyn1",
                                voxel_size=(4,4,40),
                                name="dcvsyn1")

 dataset_post.layers['postsyn.tiff'].default_view_configuration = LayerViewConfiguration(color=(57, 81, 137), alpha=20)
 dataset_post.layers['postsyn.tiff'].name = "postsyn"

@azatian
Copy link
Author

azatian commented Nov 30, 2022

Here is the associated json file, where the input shapes are now correct for all layers:

{
    "id": {
        "name": "dcvsyn1",
        "team": ""
    },
    "scale": [
        4.0,
        4.0,
        40.0
    ],
    "dataLayers": [
        {
            "name": "img",
            "category": "color",
            "boundingBox": {
                "topLeft": [
                    0,
                    0,
                    0
                ],
                "width": 160,
                "height": 160,
                "depth": 16
            },
            "elementClass": "uint8",
            "dataFormat": "wkw",
            "numChannels": 1,
            "wkwResolutions": [
                {
                    "cubeLength": 1024,
                    "resolution": [
                        1,
                        1,
                        1
                    ]
                }
            ]
        },
        {
            "name": "presyn",
            "category": "color",
            "boundingBox": {
                "topLeft": [
                    0,
                    0,
                    0
                ],
                "width": 160,
                "height": 160,
                "depth": 16
            },
            "elementClass": "uint8",
            "dataFormat": "wkw",
            "numChannels": 1,
            "defaultViewConfiguration": {
                "color": [
                    184,
                    66,
                    66
                ],
                "alpha": 20.0
            },
            "wkwResolutions": [
                {
                    "cubeLength": 1024,
                    "resolution": [
                        1,
                        1,
                        1
                    ]
                }
            ]
        },
        {
            "name": "postsyn",
            "category": "color",
            "boundingBox": {
                "topLeft": [
                    0,
                    0,
                    0
                ],
                "width": 160,
                "height": 160,
                "depth": 16
            },
            "elementClass": "uint8",
            "dataFormat": "wkw",
            "numChannels": 1,
            "defaultViewConfiguration": {
                "color": [
                    57,
                    81,
                    137
                ],
                "alpha": 20
            },
            "wkwResolutions": [
                {
                    "cubeLength": 1024,
                    "resolution": [
                        1,
                        1,
                        1
                    ]
                }
            ]
        }
    ]
}

@hotzenklotz
Copy link
Member

@jstriebel Has this issue been resolved with PR #829? Perhaps, @azatian can re-test with your new release.

@jstriebel
Copy link
Contributor

I was able to get around it by doing making individual datasets per layer but tying them with the same output path:

Great that you found a workaround, @azatian! We just released a version with a fix for the problem, version 0.10.26. Could you re-try your original code you posted above with the new version? That would be great to verify that this is indeed fixed for you.

@jstriebel
Copy link
Contributor

Closing this for now. @azatian please let us know if something is unresolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants