Dear friends
I have found a bug in ImageStack that appeared somewhere between now and 1 year ago. The method: public void addSlice(String sliceLabel, ImageProcessor ip, int n) generates an Argument out of range exception when called. Here is the way to reproduce the bug, by allocating a stack of 10 slices: ImageStack stack = new ImageStack(2, 2, 10); stack.addSlice("First slice" ,new FloatProcessor(new float[] {1, 2, 3, 4}), 1); This snippet tries to add the slice at position 2 in the stack. However, even if the stack was instantiated with 10 slices, an exception is thrown. I have found out that this is due to, in the constructor, the line 41, which put the number of slice to 0 at start: // The number of existing slices starts with 0, even if the // allocated space may be larger nSlices = 0; and to an early check in the addSlice(...) method, at lines 96-97: if (n<0 || n>nSlices) throw new IllegalArgumentException(outOfRange+n); which prevents from actually adding slices using this method in an empty stack. I understand that this method is meant to be used to insert a slice between already added slices, but since this change, we have no possibility to add slices at a given position in an empty stack. We can't modify this method to actually set the slice, because it might confuse the method getSize(), which returns the actual number of slices added, regardless of the initial capacity. So if we set the slice to erase an existing slice, the number of slice does not increase. If we add a slice to an empty position, it does. However, such a method is desirable. If we want to create a stack of 10 slices, where individual slices are added not in order, for instance by a multi-threading algorithm. So I am confused. How did we do before? Best jy -- Jean-Yves Tinevez PFID - Imagopole Institut Pasteur 25-28, rue du Docteur Roux 75724 Paris cedex 15 France tel: +33 1 40 61 31 77 |
Hi,
On Wed, 16 Jun 2010, Jean-Yves Tinevez wrote: > I have found a bug in ImageStack that appeared somewhere between now and > 1 year ago. > > The method: > > public void addSlice(String sliceLabel, ImageProcessor ip, int n) > > generates an Argument out of range exception when called. I _think_ it might be related to bug 183. Wayne said that in his test, it was still a bug in the current ImageJA. It must be something about that commit: http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=commitdiff;h=9b44e71f55e721a52796cd2284316e96a26d967c > Here is the way to reproduce the bug, by allocating a stack of 10 slices: > > ImageStack stack = new ImageStack(2, 2, 10); > stack.addSlice("First slice" ,new FloatProcessor(new float[] {1, 2, 3, 4}), > 1); > > This snippet tries to add the slice at position 2 in the stack. However, even > if the stack was instantiated with 10 slices, an exception is thrown. > > I have found out that this is due to, in the constructor, the line 41, which > put the number of slice to 0 at start: > > // The number of existing slices starts with 0, even if the > // allocated space may be larger > nSlices = 0; > > and to an early check in the addSlice(...) method, at lines 96-97: > > if (n<0 || n>nSlices) > throw new IllegalArgumentException(outOfRange+n); > > which prevents from actually adding slices using this method in an empty > stack. > > > I understand that this method is meant to be used to insert a slice between > already added slices, but since this change, we have no possibility to add > slices at a given position in an empty stack. > > We can't modify this method to actually set the slice, because it might > confuse the method getSize(), which returns the actual number of slices added, > regardless of the initial capacity. So if we set the slice to erase an > existing slice, the number of slice does not increase. If we add a slice to an > empty position, it does. > > However, such a method is desirable. If we want to create a stack of 10 > slices, where individual slices are added not in order, for instance by a > multi-threading algorithm. Actually, my understanding is that inserting should be allowed with an index pointing just after the last slice, in which case a slice would be added. Ciao, Dscho |
In reply to this post by Jean-Yves Tinevez-2
>>
> > This bug is fixed in ImageJ 1.44c. It has nSlices=size in the > ImageStack constructor instead of nSlices=0. This problem is not yet > fixed in Fiji 1.44c but Johannes is aware of it. Thank you Wayne, the problem was indeed with the Fiji version. Johannes uploaded the fix, and now it works. Again, than you very much best jy |
Free forum by Nabble | Edit this page |