These are chat archives for fiji/fiji

1st
Aug 2016
Florian Jug
@fjug
Aug 01 2016 09:07
Hi all! I have a question: what is the state-of-the-art way of resizeing an image (in java)?
I can offer the image as ImagePlus or RandomAccessibleInterval… :)
Robert Haase
@haesleinhuepf
Aug 01 2016 09:09
Hi Florian, I’m afraid, state of the art is
IJ.run(imageplus, "Scale...", "x=0.5 y=0.5 width=4095 height=2560 interpolation=Bilinear average create");
but, what about
Stefan Helfrich
@stelfrich
Aug 01 2016 09:10
ops().transform().scale(...)?
Robert Haase
@haesleinhuepf
Aug 01 2016 09:11
ops.transform.scale(img)…?
:)
Stefan Helfrich
@stelfrich
Aug 01 2016 09:11
;-)
Florian Jug
@fjug
Aug 01 2016 09:17
Thanks!
Too easy… ;)
Stefan Helfrich
@stelfrich
Aug 01 2016 09:18
Muahaha. Sounds like a good marketing punch line..
"Ops - it's too easy"
Florian Jug
@fjug
Aug 01 2016 09:19
:D
Florian Jug
@fjug
Aug 01 2016 09:47
Hmmm… ops.transform.scale seems to take only Img… is that true?
Sooo… how can I make an Img our of my RandomAccessibleInterval (without copying the whole thing)???
And… why would scale(…) only be implemented for Img?
Robert Haase
@haesleinhuepf
Aug 01 2016 09:50
it’s becasue it needs the Imgs factory to create a new img… In other words, it really creates a new image with a new pixel array in memory
probably, you’re looking for something else...
Views.interpolate(...)?
Florian Jug
@fjug
Aug 01 2016 09:54
At the end I do need a new image container (RAI, ImagePlus) containing a downscaled version of the original image.
interpolate only allows me to query the image at arbitrary coordinates I guess…
In one second I write my own downscaling method by simply using Views.interpolate and a few loops… but somehow that is a bit sad!
Oooor, you convert your ImagePlus to an Img: Img<FloatType> img = ImageJFunctions.convertFloat(imp)
Florian Jug
@fjug
Aug 01 2016 10:03
@haesleinhuepf Thanks! You would so deserve a coffee!!!
Robert Haase
@haesleinhuepf
Aug 01 2016 10:04
you’re welcome ;-)
Florian Jug
@fjug
Aug 01 2016 10:24
<fill_in_swear_words_here> @haesleinhuepf ever had the problem that making a ImagePlus our of an RAI using e.g. 'ImageJFunctions.wrapFloat( imgScaled, "scaled" )’ would result in receiving an empty image???
Anyways… we could discuss it this afternoon… don’t let me distract you all too much!
Stefan Helfrich
@stelfrich
Aug 01 2016 10:24
Was it maybe an 8-bit converted to 32-bit or something like that?
Is it really empty or is it just the visualization?
Florian Jug
@fjug
Aug 01 2016 10:27
dunno yet… i’m feeding it to an optical flow procedure which then results in giving me 0 flow everywhere… (which does NOT happen if I load the source image from file into being an ImagePlus…)
Stefan Helfrich
@stelfrich
Aug 01 2016 10:28
Ok, that's definitely odd
Let me check
Florian Jug
@fjug
Aug 01 2016 10:31
Ok, yet another question: are there ops for saving tiffs?
intuitively I tried ops.io()… ;)
Stefan Helfrich
@stelfrich
Aug 01 2016 10:32
Nope..
But there is an IOService if you have a Context already
Florian Jug
@fjug
Aug 01 2016 10:32
cool, thanks!
Stefan Helfrich
@stelfrich
Aug 01 2016 10:38
@fjug There might be an issue with the sync between your Img and ImagePlus in one of ImageJFunctions.wrapX() functions..
I also get a white image when scaling but for me it's only the representation
Florian Jug
@fjug
Aug 01 2016 10:44
Hmmm… weird...
    final IOService io = context.getService( IOService.class );
gives me null (io==null)
What am I missing?
Stefan Helfrich
@stelfrich
Aug 01 2016 10:45
I guess you'll have to change your constructor call of Context... new Context( IOService.class, OpService.class, ...)
Robert Haase
@haesleinhuepf
Aug 01 2016 11:14
@fjug regarding the wrapping thingy, we discussed that online here at some point: http://forum.imagej.net/t/how-to-wrap-any-kind-of-imageplus-to-an-imglib2-img-floattype/178/7
Florian Jug
@fjug
Aug 01 2016 11:17
Thanks guys!
Florian Jug
@fjug
Aug 01 2016 11:39
    final Context context =
            new Context( OpService.class, OpMatchingService.class, IOService.class, DatasetIOService.class, LocationService.class );
    final OpService ops = context.getService( OpService.class );
    final IOService io = context.getService( IOService.class );
    final Img< FloatType > imgScaled =
            ops.transform().scale( img, new double[] { scaleFactor, scaleFactor, 1 }, new NearestNeighborInterpolatorFactory<>() );
    try {
        System.out.println( ">>> " + scaledInputFile.getAbsolutePath() );
        io.save( imgScaled, scaledInputFile.getAbsolutePath() );
        final ImagePlus scaledImagePlus = IJ.openImage( scaledInputFile.getAbsolutePath() );
        if ( scaledImagePlus == null ) {
            System.err.println( "SUCKS!" );
        }}
Never ending story… after figuring out how to get a Context that has an IOService I try this and scaledImagePlus==null
WTF?!
Stefan Helfrich
@stelfrich
Aug 01 2016 11:43
Does the file exist on your filesystem?!
Florian Jug
@fjug
Aug 01 2016 11:44
nope… io.save doesn’t save anything… and give no error message or other indications
Stefan Helfrich
@stelfrich
Aug 01 2016 11:55
Sorry, had to debug
io.save operates on Datasets. Get a DatasetService and call datasetService.create(imgScaled) and feed it into io.save instead..
It's a little odd that one has to take that detour, but it works for me this way
Stefan Helfrich
@stelfrich
Aug 01 2016 12:00
Works, @fjug?
Florian Jug
@fjug
Aug 01 2016 12:02
I’ll try… was attempting to use IO.saveImg(…) instead, but that one flattens the hyperstack I’m attempting to save… (it seems)
Stefan Helfrich
@stelfrich
Aug 01 2016 12:03
Trying to save to tif?
Florian Jug
@fjug
Aug 01 2016 12:03
yes
Stefan Helfrich
@stelfrich
Aug 01 2016 12:15
You might run into more trouble when working with hyperstacks. While I could save a hyperstack to tiff, imagej won't recognize it as hyperstack..
Florian Jug
@fjug
Aug 01 2016 12:16
Yes… I’m there right now… :(
After loading the tiff it is indeed flattened… will this ever end??? ;)
Stefan Helfrich
@stelfrich
Aug 01 2016 12:20
Let me try something, @fjug..
Stefan Helfrich
@stelfrich
Aug 01 2016 12:28
Ok, I surrender
Florian Jug
@fjug
Aug 01 2016 12:28
Wow, seriously! I cannot save and load an hyperstack without flattening it??? Arggghhh!!!!
Stefan Helfrich
@stelfrich
Aug 01 2016 12:29
Well. There is a lot of conversions happening in this case..
Florian Jug
@fjug
Aug 01 2016 12:29
@stelfrich thanks for your help anyways… much appreciated!
Stefan Helfrich
@stelfrich
Aug 01 2016 12:29
ImagePlus -> Img -> Dataset -> File
You are basically losing all metadata in the first conversion
(afaict)
Florian Jug
@fjug
Aug 01 2016 12:30
That is a reason I understand, but makes me unhappy never the less… :(
Stefan Helfrich
@stelfrich
Aug 01 2016 12:31
I thought you could force scifio into using ome-tiff for saving and then opening it as ome-tiff again.. but that didn't work out as I expected
let's ping @ctrueden. I bet we are missing something really obvious
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 12:32
@fjug What do you mean by flattening?
Rendering the pixel data into a new array?
Stefan Helfrich
@stelfrich
Aug 01 2016 12:33
It's interpreted as a stack with c*z*t slices..
if you open that image again
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 12:33
I understand.
Stefan Helfrich
@stelfrich
Aug 01 2016 12:36
which is the only officially supported type of stack for TIFF afaik. Everything else is ImageJ specific..
Florian Jug
@fjug
Aug 01 2016 12:42
@ctrueden Summary of remaining pain: after loading and scaling I have an x,y,c,t Img<FloatType>. I would like to save that now as a hyperstack, such that fiji would load it as such. Currently fiji loads a flattened stack (not a hyperstack).
Florian Jug
@fjug
Aug 01 2016 13:06
Only way that works for me:
    final ImagePlus ip = ImageJFunctions.wrap( flow, "flow" );
    IJ.save( ip.duplicate(), flowFile.getAbsolutePath() );
Before I tried (with help, see above) to use IOService or IO.save(…)
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 13:09
I think I've had similar issues (having to duplicate the ImagePlus when using ImageJFunctions.wrap. I resorted to iterating over the z-axis, hyperslicing (Views.hyperslice), and then saving each slice of my stack as 2D image. Besides being cumbersome, I don't know if that is applicable here.
Curtis Rueden
@ctrueden
Aug 01 2016 13:55
I will try to fix IO.save et al today. I really want to avoid new code being proliferated which calls ImageJFunctions and/or IJ.save.
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 13:55
@ctrueden Thanks!
Stefan Helfrich
@stelfrich
Aug 01 2016 14:01
@ctrueden Thank you :clap:
Robert Haase
@haesleinhuepf
Aug 01 2016 14:02
@ctrueden thanks!
Curtis Rueden
@ctrueden
Aug 01 2016 14:04
Some comments after reading the thread above:
  • There are no ops for loading and saving, because that is outside the scope of the Ops project. Ops must be deterministic with no side effects. Reading and writing files constitutes side effects. That's what the IOService is for.
  • IO.save will save to whatever format you give via file extension. If you use .tiff then it is currently 3D. I will "fix" this to write the ImageJ-flavored version of TIFF that supports multiple dimensions in the TIFF comment.
However, be warned that that means your TIFF, while it will read properly back into ImageJ, will not read properly as multi-dimensional in other software that supports TIFF, because very little else supports ImageJ TIFF
  • As mentioned above, one interim solution is to use OME-TIFF instead (.ome.tif extension), which should be capable of storing 5D. But you need to put scifio-bf-compat on your runtime classpath for that. (Fiji does already)
Stefan Helfrich
@stelfrich
Aug 01 2016 14:08
@ctrueden I have unsuccessfully tried your last point.
Curtis Rueden
@ctrueden
Aug 01 2016 14:08
See also: scifio/scifio#177, scifio/scifio#288, scifio/scifio#203
@stelfrich I will do some tests today.
I want to create some integration tests for SCIFIO that validate these things long-term, to avoid regressions. However, right now it is difficult because SCIFIO/SciJava still does not have 100% proper separation of concerns regarding non-file data handles.
I have been working on this for a long time but only sporadically. It's part of the "SJC3" effort. A.k.a "robust IO"
Stefan Helfrich
@stelfrich
Aug 01 2016 14:11
I think your "solution" of writing ImageJ-flavored TIFFs as default should solve most of the problems for now. I am happy to test and write up an example / wiki page..
Curtis Rueden
@ctrueden
Aug 01 2016 14:11
  • Regarding the transform.scale stuff, @stelfrich, thank you for pushing that! Please name the new Views-based op scaleView then. We can debate whether to keep a pixel-copying version as transform.scale still.
Important note: to make copies, use the copy op. You can chain ops. Never require Img.
Gotta walk now; BBIAB.
Stefan Helfrich
@stelfrich
Aug 01 2016 14:12
@ctrueden on it
Florian Jug
@fjug
Aug 01 2016 16:04
@ctrueden @stelfrich thank both of you a lot! :beers:
I made id work somehow for now, but as soon as there is some new ‘best practice’ I’ll be happy to try it! :)
Florian Jug
@fjug
Aug 01 2016 19:32
@axtimwalde Hi Stephan! Do you plan to make ‘mpicbg_’ in any 1.x version available as (managed) non-SNAPSHOT version?
Or: does it exist somewhere?
With fiji and imageg parent poms I do only see some 0.6 versions and a 1.1.2-SNAPSHOT.
Not so important, just asking (since it could avoid some future trouble (for me))… ;)
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 19:41
Just fyi, Stephan is on the road from today until August 30. Don't expect a timely response to this.
@fjug it seems that 1.1.1 is used in the current pom-imagej on master:
https://github.com/imagej/pom-imagej/blob/master/pom.xml
Florian Jug
@fjug
Aug 01 2016 20:09
@hanslovsky 1.1.1 of mpicbg… I’d love to have mpicbg_ ;)
thanks for the info about stephans absence
Philipp Hanslovsky
@hanslovsky
Aug 01 2016 20:13
My Fiji has Fiji.app/plugins/mpicbg_-1.1.1.jar. Isn't that what you are looking for?
I just checked the pom.xml files. mpicbg_-1.1.1 poitns to pom-mpicbg-1.1.1, which in turn points to pom-fiji-17.0.0 with parent pom-imagej-14.1.0. pom-imagej-14.1.0 sets <mpicbg.version>1.0.2</mpicbg.version>.