Hello,
I'm trying to process an entire stack, but I'm having some problems. I wrote the code below in order to understand how to access to each one of the stack slices. The idea is to copy the whole stack into a matrix where each row is a slice and columns store the array of pixels for that slice. The code is very simple, but there's a problem is with "getProcessor()". It doesn't work and I don't know what I'm doing wrong, or if there is another way to get the slice without this method. ImagePlus imgSource; ... short inPixels[][] = new short[imgSource.getStack().getSize()][]; for (int stack = 0; stack < inPixels.length; stack++) { IJ.write(" *** Stack : " + stack + " / " + imgSource.getStack().getSize()); inPixels[stack] = (short[]) imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); } I also tried to look at: http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java Sincerelly, Juanjo Vega. -- Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.uam.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
Juanjo Vega a écrit :
> Hello, > > I'm trying to process an entire stack, but I'm having some problems. > > I wrote the code below in order to understand how to access to each > one of the stack slices. The idea is to copy the whole stack into a > matrix where each row is a slice and columns store the array of pixels > for that slice. > > The code is very simple, but there's a problem is with > "getProcessor()". It doesn't work and I don't know what I'm doing > wrong, or if there is another way to get the slice without this method. > > ImagePlus imgSource; > > ... > > short inPixels[][] = new short[imgSource.getStack().getSize()][]; > for (int stack = 0; stack < inPixels.length; stack++) { > IJ.write(" *** Stack : " + stack + " / " + > imgSource.getStack().getSize()); > inPixels[stack] = (short[]) > imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); > > } > > I also tried to look at: > http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java > > Sincerelly, > > Juanjo Vega. > this might sound simplistic but, you can save your stack to a folder as an image sequence, next you can process each image in that folder. Thus you will access the information for each slice in the original stack... Fabrice. -- Senger Fabrice |
Hi,
Storing it to a file is not very useful. I need to perform some affine transforms to the image so, after transforming each point, I get the new one for each slice. That's because I need to have all the slices loaded at the same time. Thanks in anyway for the idea. Sincerelly, Juanjo. Senger Fabrice escribió: > Juanjo Vega a écrit : >> Hello, >> >> I'm trying to process an entire stack, but I'm having some problems. >> >> I wrote the code below in order to understand how to access to each >> one of the stack slices. The idea is to copy the whole stack into a >> matrix where each row is a slice and columns store the array of >> pixels for that slice. >> >> The code is very simple, but there's a problem is with >> "getProcessor()". It doesn't work and I don't know what I'm doing >> wrong, or if there is another way to get the slice without this method. >> >> ImagePlus imgSource; >> >> ... >> >> short inPixels[][] = new short[imgSource.getStack().getSize()][]; >> for (int stack = 0; stack < inPixels.length; stack++) { >> IJ.write(" *** Stack : " + stack + " / " + >> imgSource.getStack().getSize()); >> inPixels[stack] = (short[]) >> imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); >> >> } >> >> I also tried to look at: >> http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java >> >> Sincerelly, >> >> Juanjo Vega. >> > Hi, > > this might sound simplistic but, you can save your stack to a folder > as an image sequence, next you can process each image in that folder. > Thus you will access the information for each slice in the original > stack... > > Fabrice. > -- Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.uam.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
Hello, Juanjo,
I am also not very sure, probably you should seperate A.B.C.D to (((A).B).C).D, try it. Juanjo Vega schrieb: > Hi, > > Storing it to a file is not very useful. I need to perform some affine > transforms to the image so, after transforming each point, I get the new > one for each slice. That's because I need to have all the slices loaded > at the same time. > > Thanks in anyway for the idea. > > Sincerelly, > > Juanjo. > > Senger Fabrice escribió: >> Juanjo Vega a écrit : >>> Hello, >>> >>> I'm trying to process an entire stack, but I'm having some problems. >>> >>> I wrote the code below in order to understand how to access to each >>> one of the stack slices. The idea is to copy the whole stack into a >>> matrix where each row is a slice and columns store the array of >>> pixels for that slice. >>> >>> The code is very simple, but there's a problem is with >>> "getProcessor()". It doesn't work and I don't know what I'm doing >>> wrong, or if there is another way to get the slice without this method. >>> >>> ImagePlus imgSource; >>> >>> ... >>> >>> short inPixels[][] = new short[imgSource.getStack().getSize()][]; >>> for (int stack = 0; stack < inPixels.length; stack++) { >>> IJ.write(" *** Stack : " + stack + " / " + >>> imgSource.getStack().getSize()); >>> inPixels[stack] = (short[]) >>> imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); >>> >>> } >>> >>> I also tried to look at: >>> http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java >>> >>> Sincerelly, >>> >>> Juanjo Vega. >>> >> Hi, >> >> this might sound simplistic but, you can save your stack to a folder >> as an image sequence, next you can process each image in that folder. >> Thus you will access the information for each slice in the original >> stack... >> >> Fabrice. >> > -- best wishes! ************************************** Guanghua Du, PhD James-Franck Str. 1 Physik Dept, E12, TUM 85748, Garching b. Muenchen Germany Tel:+49-89-28914286 E-mail: [hidden email] ************************************** |
In reply to this post by Juanjo Vega
Hello Juanjo,
This is part of a small plugin where I created a 3D array. Pixels get mapped in a Array[z][x][y] format. I hope it help. Gabriel Lapointe public void run(ImageProcessor orig) { int w = orig.getWidth(); int h = orig.getHeight(); int z = stack.getSize(); int [][][] Aori = new int[z][w][h]; for (int s = 1; s <= z; s++) { imp.setSlice(s); Aori[s-1]=orig.getIntArray(); } CleanB(Aori, 0, 255, w, h, z); CleanW(Aori, 255, 0, w, h, z); CleanE(Aori, 255, 0, w, h, z); for (int s = 1; s <= z; s++) { imp.setSlice(s); orig.setIntArray(Aori[s-1]); } } Juanjo Vega wrote: > Hello, > > I'm trying to process an entire stack, but I'm having some problems. > > I wrote the code below in order to understand how to access to each > one of the stack slices. The idea is to copy the whole stack into a > matrix where each row is a slice and columns store the array of pixels > for that slice. > > The code is very simple, but there's a problem is with > "getProcessor()". It doesn't work and I don't know what I'm doing > wrong, or if there is another way to get the slice without this method. > > ImagePlus imgSource; > > ... > > short inPixels[][] = new short[imgSource.getStack().getSize()][]; > for (int stack = 0; stack < inPixels.length; stack++) { > IJ.write(" *** Stack : " + stack + " / " + > imgSource.getStack().getSize()); > inPixels[stack] = (short[]) > imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); > > } > > I also tried to look at: > http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java > > Sincerelly, > > Juanjo Vega. > |
In reply to this post by Juanjo Vega
Hi Juanjo,
one not so intuitive point that you seem to have missed: Stack slices are not numbered 0...(n-1) but 1...n. So it should be ...getProcessor(stack+1)... (for whatever reason you name the silces 'stack', not 'slice' - this obfuscates the code somewhat) Michael _________________________________________________________ On Tue, July 7, 2009 14:30, Juanjo Vega wrote: > Hello, > > I'm trying to process an entire stack, but I'm having some problems. > > I wrote the code below in order to understand how to access to each one > of the stack slices. The idea is to copy the whole stack into a matrix > where each row is a slice and columns store the array of pixels for that > slice. > > The code is very simple, but there's a problem is with "getProcessor()". > It doesn't work and I don't know what I'm doing wrong, or if there is > another way to get the slice without this method. > > ImagePlus imgSource; > > ... > > short inPixels[][] = new short[imgSource.getStack().getSize()][]; > for (int stack = 0; stack < inPixels.length; stack++) { > IJ.write(" *** Stack : " + stack + " / " + > imgSource.getStack().getSize()); > inPixels[stack] = (short[]) > imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); > } > > I also tried to look at: > http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java > > Sincerelly, > > Juanjo Vega. > > -- > Juanjo Vega ([hidden email]) > > Unidad de Biocomputación. Laboratorio B-13. > Centro Nacional de Biotecnología. CNB-CSIC. > C\ Darwin, 3. Campus de Cantoblanco. > Universidad Autónoma de Madrid. > 28049, Madrid, Spain. > > http://www.cnb.csic.es > http://www.biocomp.cnb.uam.es > > +34 91 585 4510 > > > "Las mejores almas son capaces de los mayores vicios como de las mayores > virtudes, y aquellos que caminan despacio por el camino recto pueden > llegar más lejos que los que corren pero se apartan de él." - Discurso del > Método, René Descartes. > |
In reply to this post by Gabriel Lapointe
Your plugin looks nice. Is easier to access data in that way.
But finally I was able to manage with the slices :) Thank you! Juanjo Gabriel Lapointe escribió: > Hello Juanjo, > This is part of a small plugin where I created a 3D array. Pixels get > mapped in a Array[z][x][y] format. I hope it help. > Gabriel Lapointe > > public void run(ImageProcessor orig) > { > int w = orig.getWidth(); > int h = orig.getHeight(); > int z = stack.getSize(); > int [][][] Aori = new int[z][w][h]; > for (int s = 1; s <= z; s++) > { > imp.setSlice(s); > Aori[s-1]=orig.getIntArray(); > } > CleanB(Aori, 0, 255, w, h, z); > CleanW(Aori, 255, 0, w, h, z); > CleanE(Aori, 255, 0, w, h, z); > for (int s = 1; s <= z; s++) > { > imp.setSlice(s); > orig.setIntArray(Aori[s-1]); > } > } > > > > Juanjo Vega wrote: > >> Hello, >> >> I'm trying to process an entire stack, but I'm having some problems. >> >> I wrote the code below in order to understand how to access to each >> one of the stack slices. The idea is to copy the whole stack into a >> matrix where each row is a slice and columns store the array of pixels >> for that slice. >> >> The code is very simple, but there's a problem is with >> "getProcessor()". It doesn't work and I don't know what I'm doing >> wrong, or if there is another way to get the slice without this method. >> >> ImagePlus imgSource; >> >> ... >> >> short inPixels[][] = new short[imgSource.getStack().getSize()][]; >> for (int stack = 0; stack < inPixels.length; stack++) { >> IJ.write(" *** Stack : " + stack + " / " + >> imgSource.getStack().getSize()); >> inPixels[stack] = (short[]) >> imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels(); >> >> } >> >> I also tried to look at: >> http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java >> >> Sincerelly, >> >> Juanjo Vega. >> >> > > -- Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.uam.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
Free forum by Nabble | Edit this page |