Image subtraction then using the resulting image

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

Image subtraction then using the resulting image

h97
Dear all,

Hope you are well.

I am new to imagej and need some help with a task which is highly
appreciated.

Basically, I need to analyse thousands of images which would be excruciating
to do manually. What my goal is for example i have 500 images(frames).

1. I want to subtract two consecutive images and get the resulting image.
2. Using the resulting image from step 1 i want to make that the reference
for subtracting from frame #3. for example, frame#1-frame#2=img1. Then i
want to do the same with img1-frame#3=img2 and so on for how many number of
frames I have.

Is there any plugin available or macro to do this to automate the process?
if so, can you please tell me how to install or work with the plugin?


Thanks.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Herbie
Good day Hassan,

what you want to obtain can be done by using an ImageJ-macro or -plugin
that you need to code yourself because I doubt that somebody has written
such code.

What is missing in your description is what you consider being the
result of the operation. Is it a stack containing the images img1 to imgN ?

For macro-coding see:
<https://imagej.nih.gov/ij/developer/macro/macros.html>
<https://imagej.nih.gov/ij/developer/macro/functions.html>

Regards

Herbie

:::::::::::::::::::::::::::::::::
Am 15.09.20 um 17:45 schrieb h97:

> Dear all,
>
> Hope you are well.
>
> I am new to imagej and need some help with a task which is highly
> appreciated.
>
> Basically, I need to analyse thousands of images which would be excruciating
> to do manually. What my goal is for example i have 500 images(frames).
>
> 1. I want to subtract two consecutive images and get the resulting image.
> 2. Using the resulting image from step 1 i want to make that the reference
> for subtracting from frame #3. for example, frame#1-frame#2=img1. Then i
> want to do the same with img1-frame#3=img2 and so on for how many number of
> frames I have.
>
> Is there any plugin available or macro to do this to automate the process?
> if so, can you please tell me how to install or work with the plugin?
>
>
> Thanks.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
Perhaps i should have been more clear.

I want to save the img1 to imgN then rub a batch analysis to analyse img1 to
imgN to get area of particles.





--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Cammer, Michael-3
I think I understand what you wat to do.

A macro to do this frame by frame is simple but slow.  This is much faster.

If you have enough memory.
Duplicate a stack.
Add a frame to the beginning of one stack.
Add a frame to the end of the other stack.
Subtract one from the other or difference them.

Regards-

Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory
NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY  10016
Office: 646-501-0567 Cell: 914-309-3270  [hidden email]  
http://nyulmc.org/micros  http://microscopynotes.com/
 





-----Original Message-----
From: h97 <[hidden email]>
Sent: Tuesday, September 15, 2020 12:31 PM
To: [hidden email]
Subject: Re: Image subtraction then using the resulting image

[EXTERNAL]

Perhaps i should have been more clear.

I want to save the img1 to imgN then rub a batch analysis to analyse img1 to imgN to get area of particles.





--
Sent from: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.1557.x6.nabble.com_&d=DwICAg&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=hKcYiGa59JmlrIRx7FQuqdRKrQLEzsl1wZH4UO-QCSY&s=CQwlEAJJnGqsEr2KU08idWGaHRYeGeKwIjqrboXrFOU&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwICAg&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=hKcYiGa59JmlrIRx7FQuqdRKrQLEzsl1wZH4UO-QCSY&s=j3EuZ1orUta7qjd_wrqHmZS68AHJbTuVkis-LYvYs5c&e=

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Herbie
In reply to this post by h97
Understood, in the end you want to see N = 499 single images.

I suppose that your original stack of 500 images is of 32bit float
format, otherwise you will encounter problems with the subtractions.
Is this correct?

Regards

Herbie

_________________________________
Am 15.09.20 um 18:31 schrieb h97:
> Perhaps i should have been more clear.
>
> I want to save the img1 to imgN then rub a batch analysis to analyse img1 to
> imgN to get area of particles.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
In reply to this post by Cammer, Michael-3
can you tell me more about the macro?

also, i see where you are going with this but that would require a lot of
memory and why would i need to add frames?

Thanks



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
In reply to this post by Herbie
yes that is correct.

but i think i will need to change to 8 bit or 16 bit to threshold the image
to analyse the images to get particle area.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Herbie
You can threshold the resulting 32bit images as well.

Am 15.09.20 um 19:10 schrieb h97:
> yes that is correct.
>
> but i think i will need to change to 8 bit or 16 bit to threshold the image
> to analyse the images to get particle area.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Fred Damen
In reply to this post by Herbie
Greetings Hassan,

Let me preface this with the fact that lately rarely write macros, and as
such, there may be a much better way of doing this.

The macro language likes to operate on the current image that does not
seem to be explicitly referenced.  When you do need to reference a
specific image, you can refer to the image by its title/name or its ID. So
after operating on an image, rename it to something unique that you can
reference.

So somethings that may get you started a little quicker. Extracting a
frame, you can use Image>Stacks>Tools>Make Substack... to extract the
particular slice of interest; Image>Rename... to rename the extracted
frame; Process>Image Calculator... to do the subtraction. Using
Plugins>Macros>Record... got me this to put into the macro you can write
given the aforementioned references:
selectWindow("Trace - Untitled");
run("Make Substack...", "slices=1-24 frames=1");
rename("A");
selectWindow("Trace - Untitled");
run("Make Substack...", "slices=1-24 frames=2");
rename("B");
imageCalculator("Subtract create 32-bit stack", "A","B");
selectWindow("Result of A");
rename("C");

Note however I would warn that if a image becomes current at the wrong
time this will mess up.  Generally not an issue for a few frames, but for
500 you may want to consider writing a plugin.  I have written a plugin
called F_Project that does similar but different functionality.
https://imagej.net/Frames

Enjoy,

Fred

PS. An after thought, you should be able to do the whole subtraction
without a loop.




On Tue, September 15, 2020 11:17 am, Herbie wrote:

> Good day Hassan,
>
> what you want to obtain can be done by using an ImageJ-macro or -plugin
> that you need to code yourself because I doubt that somebody has written
> such code.
>
> What is missing in your description is what you consider being the
> result of the operation. Is it a stack containing the images img1 to imgN
> ?
>
> For macro-coding see:
> <https://imagej.nih.gov/ij/developer/macro/macros.html>
> <https://imagej.nih.gov/ij/developer/macro/functions.html>
>
> Regards
>
> Herbie
>
> :::::::::::::::::::::::::::::::::
> Am 15.09.20 um 17:45 schrieb h97:
>> Dear all,
>>
>> Hope you are well.
>>
>> I am new to imagej and need some help with a task which is highly
>> appreciated.
>>
>> Basically, I need to analyse thousands of images which would be
>> excruciating
>> to do manually. What my goal is for example i have 500 images(frames).
>>
>> 1. I want to subtract two consecutive images and get the resulting
>> image.
>> 2. Using the resulting image from step 1 i want to make that the
>> reference
>> for subtracting from frame #3. for example, frame#1-frame#2=img1. Then i
>> want to do the same with img1-frame#3=img2 and so on for how many number
>> of
>> frames I have.
>>
>> Is there any plugin available or macro to do this to automate the
>> process?
>> if so, can you please tell me how to install or work with the plugin?
>>
>>
>> Thanks.
>>
>>
>>
>> --
>> Sent from: http://imagej.1557.x6.nabble.com/
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
In reply to this post by Herbie
that makes it easier. So do you have any reference that could help me in
writing the macro i.e subtracting the consecutive frames then saving the
resultant image?



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Herbie
As far as I understand your initial wish, you don't want to subtract
*consecutive* frames:

slice1 - slice2   = img1
img1   - slice3   = img2
img2   - slice4   = img3
...
imgN-1 - sliceN+1 = imgN

(N+1 = 500)

Regards

Herbie

:::::::::::::::::::::::::::::::::
Am 15.09.20 um 19:38 schrieb h97:

> that makes it easier. So do you have any reference that could help me in
> writing the macro i.e subtracting the consecutive frames then saving the
> resultant image?
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
yes that is correct. apologies for the mix up last time.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

Herbie
In reply to this post by h97
In the sequel please find an ImageJ-macro that does what you've
described in your first post:

/* imagej-macro "subtractionScheme" (Herbie G., 15. Sept. 2020) */
requires("1.53d");
run("MRI Stack"); // load a demo stack
run("32-bit");
stack = getImageID();
n = nSlices + 1;

run("Make Substack...", "  slices=1");
s1 = getTitle();
selectImage(stack);
run("Make Substack...", "  slices=2");
run("Multiply...", "value=-1");
s2 = getTitle();
imageCalculator("add", s2, s1);
close(s1);
rename("img1");

for ( i=3; i<n; i++ ) {
    k = i - 1;
    j = i - 2;
    selectImage(stack);
    run("Make Substack...", "  slices="+i);
    run("Multiply...", "value=-1");
    s = getImageID();
    imageCalculator("add", s, "img"+j);
    rename("img"+k);
}
exit();
/* imagej-macro "subtractionScheme" (Herbie G., 15. Sept. 2020) */

Paste the above macro code to an empty macro window (Plugins >> New >>
Macro) and run it.
(You need an open internet connection to load the demo stack.)

The demo stack has 27 slices (frames) which means that you will get 26
result images.

HTH

Herbie

:::::::::::::::::::::::::::::::::
Am 15.09.20 um 17:45 schrieb h97:

> Dear all,
>
> Hope you are well.
>
> I am new to imagej and need some help with a task which is highly
> appreciated.
>
> Basically, I need to analyse thousands of images which would be excruciating
> to do manually. What my goal is for example i have 500 images(frames).
>
> 1. I want to subtract two consecutive images and get the resulting image.
> 2. Using the resulting image from step 1 i want to make that the reference
> for subtracting from frame #3. for example, frame#1-frame#2=img1. Then i
> want to do the same with img1-frame#3=img2 and so on for how many number of
> frames I have.
>
> Is there any plugin available or macro to do this to automate the process?
> if so, can you please tell me how to install or work with the plugin?
>
>
> Thanks.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
h97
Reply | Threaded
Open this post in threaded view
|

Re: Image subtraction then using the resulting image

h97
i will definitely and let you know how it goes. much appreciated.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html