problem with addslice

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with addslice

Peter Nagy-2
Hi List members,
I have tried to write a plugin, and I have problems with addslice.
The plugin extracts pixels in the range [100:200,100:200] from every
slice and creates a new stack from these. The pixel values are
extracted from each slice, and put into an array called 'newpixels0',
and then these values are added to a new stack with the addslice
method. However, the new stack contains identical slices corresponding
to the last slice of the original image. Can anyone tell me why?
Thank you,
Peter




public void run(ImageProcessor oldproc) {

byte [] newpixels0,pixels0;
ImageProcessor ip;
int w=oldproc.getWidth();
int h=oldproc.getHeight();
int z=oldimplus.getStackSize();
ImageStack oldstack=oldimplus.getStack();
ImageStack s=new ImageStack(100,100);
ImageProcessor temp_ip=oldproc.createProcessor(100,100);
newpixels0=new byte[100*100];
pixels0=new byte[w*h];
for (int i=1;i<=z;i++) {
pixels0=(byte []) oldstack.getPixels(i);
for (int y=100;y<200;y++) {
int offset1_image=y*w;
int offset1_roi=(y-100)*100;
for (int x=100;x<200; x++) {
newpixels0[offset1_roi+x-100]=pixels0[offset1_image+x];
}
}
s.addSlice(null,newpixels0);
}
new ImagePlus("RGB",s).show();
}
Reply | Threaded
Open this post in threaded view
|

Re: problem with addslice

Albert Cardona
Hi Peter,

You are reusing variables, so all slices end up pointing to the same
pixels array, which is that of the last.

Albert