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

set plane coordinates #65

Merged
merged 4 commits into from
Jul 6, 2023
Merged

Conversation

jburel
Copy link
Contributor

@jburel jburel commented Jul 5, 2023

This PR fixes an issue when setting the plane associated to a given shape.
The current implementation does not handle images with for example t=1, z=1 and c>1.
This is based on https://github.com/ome/omero-insight/blob/master/src/main/java/org/openmicroscopy/shoola/util/roi/io/ROIReader.java#L227

@jburel jburel closed this Jul 5, 2023
@jburel jburel reopened this Jul 5, 2023
@ppouchin
Copy link
Member

ppouchin commented Jul 5, 2023

Ok. It fails because in some tests, ROIs exist without images.
Maybe the "position -> C / Z / T" conversion would work when saving the ROI to an image?

@jburel
Copy link
Contributor Author

jburel commented Jul 5, 2023

If the image is accessible from the roi it will work
roi.getImage() will not be null and it will allow to perform the check
Unfortunately the ImagePlus object is null in the current implementation.

@ppouchin
Copy link
Member

ppouchin commented Jul 5, 2023

I have a proposition (currently running test locally):

    protected void copyFromIJRoi(ij.gui.Roi ijRoi) {
        LengthI size          = new LengthI(ijRoi.getStrokeWidth(), UnitsLength.POINT);
        Color   defaultStroke = Optional.ofNullable(Roi.getColor()).orElse(Color.YELLOW);
        Color   defaultFill   = Optional.ofNullable(Roi.getDefaultFillColor()).orElse(TRANSPARENT);
        Color   stroke        = Optional.ofNullable(ijRoi.getStrokeColor()).orElse(defaultStroke);
        Color   fill          = Optional.ofNullable(ijRoi.getFillColor()).orElse(defaultFill);
        data.getShapeSettings().setStrokeWidth(size);
        data.getShapeSettings().setStroke(stroke);
        data.getShapeSettings().setFill(fill);
        
        // Set the plane 
        int c = ijRoi.getCPosition();
        int z = ijRoi.getZPosition();
        int t = ijRoi.getTPosition();
        
        ij.ImagePlus ip = ij.WindowManager.getImage(ijRoi.getImageID()); //ijRoi.getImage() returns null
        if (ip != null) {
            int pos       = ijRoi.getPosition();
            int stackSize = ip.getStackSize();
            int imageC    = ip.getNChannels();
            int imageT    = ip.getNFrames();
            int imageZ    = ip.getNSlices();
            if (stackSize == imageZ) {
                z = pos;
                //reset values
                c = 1;
                t = 1;
            } else if (stackSize == imageC) {
                c = pos;
                //reset values
                z = 1;
                t = 1;
            } else if (stackSize == imageT) {
                t = pos;
                //reset values
                c = 1;
                z = 1;
            }
        }
        data.setC(Math.max(-1, c - 1));
        data.setZ(Math.max(-1, z - 1));
        data.setT(Math.max(-1, t - 1));
    }

@jburel
Copy link
Contributor Author

jburel commented Jul 5, 2023

Feel free to close the PR if your suggestion works or adjust my commits

@ppouchin
Copy link
Member

ppouchin commented Jul 5, 2023

Ok. I need to check in ImageJ if it works to be sure, but the tests pass.

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Patch coverage: 96.00% and project coverage change: -0.04 ⚠️

Comparison is base (f831aa0) 95.53% compared to head (7ce4bfe) 95.50%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #65      +/-   ##
============================================
- Coverage     95.53%   95.50%   -0.04%     
- Complexity     1139     1143       +4     
============================================
  Files            45       45              
  Lines          3026     3048      +22     
  Branches        236      242       +6     
============================================
+ Hits           2891     2911      +20     
  Misses           78       78              
- Partials         57       59       +2     
Impacted Files Coverage Δ
...n/java/fr/igred/omero/roi/GenericShapeWrapper.java 97.36% <96.00%> (-0.33%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jburel
Copy link
Contributor Author

jburel commented Jul 6, 2023

@ppouchin I will do some tests with the workflow I have in place already later on

@jburel
Copy link
Contributor Author

jburel commented Jul 6, 2023

With the latest set of commits, using the workflow I used for testing, the problem is no longer visible

@ppouchin ppouchin merged commit 9fa488b into GReD-Clermont:main Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants