Can anyone suggest a way to compare two images (in a stack from an original video) and find out how many pixels are different in the second, relative to the first? Each image is 8-bit B/W, so what I'd like to count is the sum of exactly how many black pixels become white and vice versa from one slice to the next. I'm dealing with stacks of approximately 500 images, and would like to generate an integer string from these comparisons.
Thanks much for any help! |
I don't really know what is "black" and "white" for an 8-bit images (is it 0
to 255 or jsut the intensity value changes fromlike 22 to 168 ?) Anyway it's pretty straightforward, just duplicate your stack, remove the first slices of the duplicate, and make the difference image beetween the Nth slice of the original and duplicate stacks (Process > Image Calculator). Loop from N=0 to N=nSlices-2 and store all results in a new, (N-1) slices stack. Then you can just use "measure" to find how many pixels are different from zero (that is, are different btween two consecutive slices). Christophe On Mon, May 18, 2009 at 3:16 PM, martenszeus <[hidden email]> wrote: > Can anyone suggest a way to compare two images (in a stack from an original > video) and find out how many pixels are different in the second, relative > to > the first? Each image is 8-bit B/W, so what I'd like to count is the sum of > exactly how many black pixels become white and vice versa from one slice to > the next. I'm dealing with stacks of approximately 500 images, and would > like to generate an integer string from these comparisons. > Thanks much for any help! > -- > View this message in context: > http://n2.nabble.com/Counting-overall-pixel-change-tp2932920p2932920.html > Sent from the ImageJ mailing list archive at Nabble.com. > |
In reply to this post by martenszeus
Hi Peter,
the easiest would be to convert the stack into single images (Image>Stack>Stack to Images) and then have a macro step though. If nothing else is open, you can use this macro: for (i=1; i<nImages; i++) { imageCalculator("Difference create", i,i+1); setThreshold(1, 255); //use (2, 255) for one level tolerance, etc. run("Convert to Mask"); getRawStatistics(nPixels, mean); print(d2s(mean*nPixels/255, 0)); close(); } Michael ________________________________________________________________ On 18 May 2009, at 15:16, martenszeus wrote: > Can anyone suggest a way to compare two images (in a stack from an > original > video) and find out how many pixels are different in the second, > relative to > the first? Each image is 8-bit B/W, so what I'd like to count is > the sum of > exactly how many black pixels become white and vice versa from one > slice to > the next. I'm dealing with stacks of approximately 500 images, and > would > like to generate an integer string from these comparisons. > Thanks much for any help! |
In reply to this post by lechristophe
Here is how to compute the substracted stack from the input stack :
Title=getTitle(); N=nSlices; run("Duplicate...", "title=Temp duplicate range=1-"+N); run("Delete Slice"); selectWindow(Title); setSlice(N); run("Delete Slice"); imageCalculator("Subtract create 32-bit stack", Title,"Temp"); Here you generate a 32-bit image that stroes the difference (can be negative or positive), but if you're only interested about how many pixels change (and not the value by which they change), you can use "Difference" instead of "Substract" in the Image Calculator. Christophe On Mon, May 18, 2009 at 3:42 PM, Christophe Leterrier <[hidden email]> wrote: > > I don't really know what is "black" and "white" for an 8-bit images (is it 0 to 255 or jsut the intensity value changes fromlike 22 to 168 ?) > > Anyway it's pretty straightforward, just duplicate your stack, remove the first slices of the duplicate, and make the difference image beetween the Nth slice of the original and duplicate stacks (Process > Image Calculator). Loop from N=0 to N=nSlices-2 and store all results in a new, (N-1) slices stack. Then you can just use "measure" to find how many pixels are different from zero (that is, are different btween two consecutive slices). > > Christophe > > On Mon, May 18, 2009 at 3:16 PM, martenszeus <[hidden email]> wrote: >> >> Can anyone suggest a way to compare two images (in a stack from an original >> video) and find out how many pixels are different in the second, relative to >> the first? Each image is 8-bit B/W, so what I'd like to count is the sum of >> exactly how many black pixels become white and vice versa from one slice to >> the next. I'm dealing with stacks of approximately 500 images, and would >> like to generate an integer string from these comparisons. >> Thanks much for any help! >> -- >> View this message in context: http://n2.nabble.com/Counting-overall-pixel-change-tp2932920p2932920.html >> Sent from the ImageJ mailing list archive at Nabble.com. > |
Free forum by Nabble | Edit this page |