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

StarDist loses image calibration #10

Open
tischi opened this issue May 7, 2021 · 12 comments
Open

StarDist loses image calibration #10

tischi opened this issue May 7, 2021 · 12 comments

Comments

@tischi
Copy link

tischi commented May 7, 2021

@uschmidt83 @maweigert @lacan @haesleinhuepf

When running StarDist in Fiji on an image the output image has lost the calibration.
It would be very nice to have the same calibration as the input image.

I think it could be as easy as:

Calibration calibration = inputImagePlus.getCalibration();
// do the segmentation
outputImagePlus.setCalibration( calibration.copy() ); // .copy() is important to not change the input calibration
@uschmidt83
Copy link
Member

Hi @tischi, sorry for taking so long to reply.

I'm not sure it's that easy, since the output (label) images will typically have a different data type and may have different numbers of channels as compare to the input image. One could maybe selectively copy the relevant calibration parameters?

Furthermore, we use ImageJ2 Datasets, and I'm not sure how to deal with calibration info there.

@tischi
Copy link
Author

tischi commented Jul 12, 2021

I'm not sure it's that easy

It think it is that easy 😄 , because the imagePlus calibration does not care about the number of channels and data-type.

Furthermore, we use ImageJ2 Datasets, and I'm not sure how to deal with calibration info there

But, I strongly assume that to finally display the image you do something like:

ImagePlus imp = ImageJFunctions.wrap( );
imp. show();

Do you?

@uschmidt83
Copy link
Member

It think it is that easy 😄 , because the imagePlus calibration does not care about the number of channels and data-type.

Are you sure? Where can I find out what can be stored in the calibration data?

But, I strongly assume that to finally display the image you do something like:

ImagePlus imp = ImageJFunctions.wrap( );
imp. show();

Do you?

No, we return Datasets which (I assume) are implicitly converted to whatever is needed.

@tischi
Copy link
Author

tischi commented Jul 12, 2021

I see, some SciJava magic that's converting to and from ImagePlus.
Then I don't know either. Maybe @imagejan knows how to deal with voxel sizes and Datasets?

@imagejan
Copy link

imagejan commented Jul 12, 2021

The imagej-legacy layer takes care of translating between org.scijava.Dataset and ij.ImagePlus, including the metadata (although there might be some issues with IJ1<->IJ2 synchronization after updating an object that was already synchronized, see the open issues in imagej-legacy).

You can set the image calibration by setting or modifying the dataset's CalibratedAxis objects, e.g. (I assume) by taking copies of the axes of the original dataset, or by creating a new net.imagej.axis.DefaultLinearAxis with the appropriate constructors including the scale and unit.

Maybe @ctrueden has an illustrative code example somewhere on gist already?

@uschmidt83
Copy link
Member

I think it could be as easy as:

Calibration calibration = inputImagePlus.getCalibration();
// do the segmentation
outputImagePlus.setCalibration( calibration.copy() ); // .copy() is important to not change the input calibration

I'm assuming you already do this in your script that calls StarDist and don't actually have a problem with losing image calibration? I.e. this feature would be nice to have, but isn't an actual problem for you?

@tischi
Copy link
Author

tischi commented Jul 21, 2021

I'm assuming you already do this in your script that calls StarDist

I don't call call StarDist via a script but via the GUI. So it is an actual problem. I think this goes beyond "nice to have". I would expect from a good Fiji plugin that it passes on the image calibration onto the output images 😄

@maweigert
Copy link
Member

Hi @tischi ,

I agree, that keeping the calibration might be desirable ;)

See PR #13 for a first try to do this via label.setAxes(CalibratedAxis[]) (should already work)

Thanks for notifying!

M

@uschmidt83 uschmidt83 changed the title StarDist looses image calibration StarDist loses image calibration Jul 21, 2021
@uschmidt83
Copy link
Member

I just refactored the code to work more generally. I'd consider this done if there are no objections.

@tischi
Copy link
Author

tischi commented Nov 9, 2021

@uschmidt83

Did you already upload those changes to the Fiji plugin? We recently tried and it seems to still loose the calibration.

@uschmidt83
Copy link
Member

Hi @tischi, the changes (#13) haven't been merged yet.

I'm doing this all in my spare time and can't even develop on my main machine, because tensorflow doesn't properly run in Java on M1 Macs. It will be merged eventually...

@tischi
Copy link
Author

tischi commented Nov 9, 2021

I'm doing this all in my spare time and can't even develop on my main machine, because tensorflow doesn't properly run in Java on M1 Macs. It will be merged eventually...

Sure, fully understood. Thanks for still working on this!

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

No branches or pull requests

4 participants