Changing pixel values in a stack

57 views
Skip to first unread message

Behdad Pouran

unread,
Jun 25, 2015, 8:09:06 AM6/25/15
to bonej-users-a...@googlegroups.com
Dear all,

I'm using FIJI and would like to convert the pixel values between 0 and 25
to 30. I have created the following code but when the stack contains more
than a certain number of slices it fails to cover the whole pixels. Could
you please assist me with this problem? Is there a faster way available?

This is the code:

v1=0;

v2=25;

v3=30;

O=getWidth();

Y=getWidth();

Z=getSliceNumber();

for (k = 1; k <= Z; k++){

for (i = 0; i <= O; i++){

for (j = 0; j <= Y; j++){

changeValues(v1, v2, v3);

}

}

}

Thank you very much in advance.

michae...@gmail.com

unread,
Jun 25, 2015, 9:33:14 AM6/25/15
to bonej-users-a...@googlegroups.com
Hi Behdad,

You should use nSlices() to set your Z variable and also you have to tell your loop which pixel you are changing. At the moment you call changeValues() but with no reference to a location. Look at setPixel() and setSlice() methods.

Michael
> --
> You received this message because you are subscribed to the Google Groups "BoneJ Users and Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bonej-users-and-dev...@googlegroups.com.
> To post to this group, send email to bonej-users-a...@googlegroups.com.
> Visit this group at http://groups.google.com/group/bonej-users-and-developers.
> For more options, visit https://groups.google.com/d/optout.
>

--
Sent from my Jolla

Richard Domander

unread,
Oct 14, 2015, 5:16:02 AM10/14/15
to BoneJ Users and Developers
Hi Behdad,

I believe that the loop termination conditions for i and j  should be i < O and j < Y.
In addition the initialization of O should be O = getHeight();

Best Regards,
Richard Domander

Michael Doube

unread,
Oct 14, 2015, 5:44:31 AM10/14/15
to bonej-users-a...@googlegroups.com
Additionally, Z should be initialised to:

Z = nSlices();

getSliceNumber() returns the index of the current slice, not the number of slices in the stack.

See http://rsbweb.nih.gov/ij/developer/macro/functions.html for documentation on macro functions.

For historical reasons, slice numbers start at 1 so you are correct to iterate from 1 to Z inclusive (i.e. with a <=) . But, (x,y) coordinates start at 0 so you must end your row and column loops with < and not <= else you will go beyond the end of the pixel array.

Michael
--
Reply all
Reply to author
Forward
0 new messages