Re: Image subtraction then using the resulting image

Posted by Fred Damen on
URL: http://imagej.273.s1.nabble.com/Image-subtraction-then-using-the-resulting-image-tp5023935p5023942.html

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