Support the Arctic Sea Ice Forum and Blog

Author Topic: Creating Animated GIFs  (Read 105943 times)

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #100 on: July 06, 2019, 03:44:13 PM »
Let me know if you keep getting stuck in the same place. It's easy to miss out a step when writing instructions. Adjusting contrast before rgb compose may have a more striking effect, but only you know what you're aiming for :)

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 318
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #101 on: July 22, 2019, 01:47:22 AM »
Following up on: https://forum.arctic-sea-ice.net/index.php/topic,2591.msg214848.html#msg214848 . Not sure if this is the best thread for this, since I actually just use EZGif's website to make the GIFs once I've created the images, but it can always be moved if appropriate...

Repeating the summary from the thread above:
Quote
I do it using the imageJ API (Java code), basically by: for each day, reading in the 5 preceding days' images, converting each pixel color to a concentration value based on the Bremen key, taking the median for each pixel, then creating a new image. (Actually, the algorithm is easily changed -- 5 day median is quite conservative.)

The code is a bit of a hack, so I'll just post some snippets:

0. Make a key to convert colors to concentrations. The key was made by using the ImageJ GUI to manually pick indices corresponding to each color in the key of one particular image. (ImageJ LUT objects store pixel values as a 1d array; indices refer to that array.)
Quote
int[] concBuckets = {10, 20, 30, 40, 50, 60, 70, 80, 85, 90, 95, 99,100};
int[] indices = {14, 84, 92,104,110,105, 80,100,124,170, 79,177,174}; 
for (int i=0; i<concBuckets.length; i++) {
   this.rgbToConc.put(
      this.keyImage.getProcessor().getLut().getRGB(indices), concBuckets);
}

For each day do all of the following steps:
Quote
for (int n=0; n < this.nDays; n++) { ... }

1. Download the needed number of preceding images (e.g. five, if making a trailing 5-day median) from their URLs or get from cache if already downloaded. URLs are similar to (substitute the dates):
 - https://seaice.uni-bremen.de/data/amsr2/asi_daygrid_swath/n6250/2017/jul/Arctic/asi-AMSR2-n6250-20170731-v5_nic.png
Quote
ImagePlus image = null;
String filename = this.getFilename(date, bremenVersion);
File file = new File(this.cacheDir + filename);
if (file.exists()) {
            System.out.println("Loading image from file: " + this.cacheDir + filename);
            image = new ImagePlus(this.cacheDir + filename);
} else {
            String url = this.getUrl(date, filename);
            System.out.println("Downloading image from web: " + url);
            image = new ImagePlus(url);
}

2. For each preceding image, convert the colors to concentrations using the key.
Quote
int[] conc = new int[this.len];
LUT lut = ip.getLut();
byte[] pixels = (byte[]) ip.getPixels();
for (int y=0; y < ip.getHeight(); y++) {
            for (int x=0; x < ip.getWidth(); x++) {
                int i = x + y * ip.getWidth();
                int rgb = lut.getRGB(pixels);
                if (this.rgbToConc.containsKey(rgb)){
                    conc = Integer.parseInt(this.rgbToConc.get(rgb).toString());
                } else {
                    conc = Integer.MAX_VALUE;
                }
            }
}

3. Use this set of concentrations to calculate the output values; e.g. for median (i.e. quartile = 2):
Quote
for (int i=0; i<this.len; i++) {
            int filteredC = this.concentrations.get(0);
            int[] values = new int[this.concentrations.size()];
            for (int z=0; z<values.length; ++z) {
                values[z] = this.concentrations.get(z);
            }
            Arrays.sort(values);
            if (values.length % 2 == 0) {
                throw new RuntimeException("Can't use quartile for even number of ice concentrations.");
            } else {
                int q1 = values.length/4;   // for values.length == 5, q1 == 1 (floor of 1.25)
                filteredC = values[q1*quartile];
            }
            this.filteredConcs = filteredC;
}

4. Finally, convert the concentrations back into RGB color values and use that as the pixel array to generate a new image.

5. Now I have a set of images, each being the (e.g.) 5-day trailing median. I just use EZGif online to convert them to an animation. To use a different algorithm, just change step 3.

« Last Edit: July 22, 2019, 02:05:58 AM by petm »

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #102 on: July 22, 2019, 10:41:18 PM »
thanks petm, useful stuff

Sterks

  • Guest
Re: Creating Animated GIFs
« Reply #103 on: July 25, 2019, 09:46:01 PM »
Following up on: https://forum.arctic-sea-ice.net/index.php/topic,2591.msg214848.html#msg214848 . Not sure if this is the best thread for this, since I actually just use EZGif's website to make the GIFs once I've created the images, but it can always be moved if appropriate...

Repeating the summary from the thread above:
Quote
I do it using the imageJ API (Java code), basically by: for each day, reading in the 5 preceding days' images, converting each pixel color to a concentration value based on the Bremen key, taking the median for each pixel, then creating a new image. (Actually, the algorithm is easily changed -- 5 day median is quite conservative.)

The code is a bit of a hack, so I'll just post some snippets:

I don’t think I have the Java skills to achieve this in a reasonable time. Thank you anyway and hope you post more filtered gifs when you find the time. I really enjoy them, I don’t think five day average is conservative, actually it leaves the shortest characteristic time that makes sense. Weather patterns change with that pace usually, not faster.

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 318
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #104 on: August 08, 2019, 01:50:40 AM »
Oof, it turns out I made an error in calculating the index for getting median values from a sorted array. The calculation was only correct for 5-day medians (zero-based index 2). For 3-day medians it was returning the minimum (index 0; should be index 1).

However, this may have been a fortunate error, as it turns out that I actually like the minimum algorithm. It's not conservative, but if it's true that the biggest artifacts are clouds, then this does the best job of eliminating them. On the other hand, maybe it overestimates the amount of melt too much?

Attached is a gif that cycles through each index for today's result. Index 0 is minimum, 2 is median, 4 is maximum, and 1 and 3 are intermediate (something like Q1 and Q3).

Click to animate.

Any comments?

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #105 on: August 08, 2019, 02:03:59 AM »
Any comments?
Run all 5 over the last 5years and anecdotally compare them to available clear worldview days. Then satisfy yourself which is best. I'll be very grateful :)

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 318
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #106 on: August 08, 2019, 02:05:09 AM »
Any comments?
Run all 5 over the last 5years and anecdotally compare them to available clear worldview days. Then satisfy yourself which is best. I'll be very grateful :)

Good idea. I'd be interested to see as well. It'll have to wait for the weekend though...

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #107 on: August 08, 2019, 02:10:28 AM »
well, maybe not 5yrs

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 318
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #108 on: August 08, 2019, 02:13:30 AM »
lol  :D

I'll find some good examples and see if there's a clear trend.

El Cid

  • Young ice
  • Posts: 2507
    • View Profile
  • Liked: 923
  • Likes Given: 225
Re: Creating Animated GIFs
« Reply #109 on: August 08, 2019, 08:06:50 AM »
If you find out which one is best, please tell us about it and you could also post it on the main thread as it is important and educative

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #110 on: August 08, 2019, 12:08:04 PM »
Thinking about it overnight, a median has its uses but I prefer the detail of the daily. Weather artifacts are easy to see in an animation and add further information.

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #112 on: May 30, 2020, 02:47:28 PM »
forgot about sst in post above but it doesn't matter now...
Quote
Real-time, global, sea surface temperature (RTG_SST_HR) analysis
ATTENTION! This product was discontinued on Feb. 11, 2020


Posting this method from A-Team for future reference
Quote
split nullschool montage into rgb components to get the high velocity component of the 70 hPa winds (the red channel), then overlay as ‘lighten only’.
best viewed full screen

blumenkraft

  • Guest
Re: Creating Animated GIFs
« Reply #113 on: May 30, 2020, 03:09:37 PM »
Wow, that's amazing!

I do see some correlation.

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #114 on: June 08, 2020, 09:16:19 PM »
Reverse engineering Wipneus' piomas mp4, 1979-2018 to get daily png files (well, every 5days).
ffmpeg -i piomas.mp4 frame%04d.png
creates 2,920 frames, ~1GB, gifs might be smaller.




Freegrass

  • Young ice
  • Posts: 3825
  • Autodidacticism is a complicated word...
    • View Profile
  • Liked: 951
  • Likes Given: 1251
Re: Creating Animated GIFs
« Reply #115 on: June 08, 2020, 09:44:22 PM »
forgot about sst in post above but it doesn't matter now...
Quote
Real-time, global, sea surface temperature (RTG_SST_HR) analysis
ATTENTION! This product was discontinued on Feb. 11, 2020


Posting this method from A-Team for future reference
Quote
split nullschool montage into rgb components to get the high velocity component of the 70 hPa winds (the red channel), then overlay as ‘lighten only’.
best viewed full screen
I love those ASCAT animations. It would be great if we could overlay Nullschool wind graphics over that ice movement...
90% of the world is religious, but somehow "love thy neighbour" became "fuck thy neighbours", if they don't agree with your point of view.

WTF happened?

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #116 on: June 08, 2020, 11:27:52 PM »
Ideally, read this whole thread but...
Start here for background info on ascat.

Then scroll down to here for shorter instructions except that ospo doesn't appear to have the files anymore.
At the moment they can be downloaded  from
https://manati.star.nesdis.noaa.gov/ascat_images/ice_image/msfa-NHe-a-2020159.sir.gif
Change the day numbers.

Once you have a nice ascat ani you can move on to gimp for nullschool overlays.

Freegrass

  • Young ice
  • Posts: 3825
  • Autodidacticism is a complicated word...
    • View Profile
  • Liked: 951
  • Likes Given: 1251
Re: Creating Animated GIFs
« Reply #117 on: June 08, 2020, 11:37:32 PM »
Thanks Uniquorn. I'll try to figure it out later.  :)
90% of the world is religious, but somehow "love thy neighbour" became "fuck thy neighbours", if they don't agree with your point of view.

WTF happened?

Freegrass

  • Young ice
  • Posts: 3825
  • Autodidacticism is a complicated word...
    • View Profile
  • Liked: 951
  • Likes Given: 1251
Re: Creating Animated GIFs
« Reply #118 on: August 12, 2020, 10:10:03 AM »
My GIMP skills are very limited, and so I would love to learn more.

The way I make my forecast GIFs is very easy.
  • I make one screenshot and throw it away. Because the first screenshot of the day doesn't get a number and thus ends up as the last file.
  • I open Nullschool, go back 3 or 6 hours depending on the hour, and I take 41 screenshots. Make sure you select UTC time instead of local time! Set Nullschool to your prefered view, and bookmark it so you always get the same view when you open it.
  • I open GIMP and I open the screenshot as layers.
  • After all the screenshots are imported, I use the fixed crop tool to cut out the area I want.
  • I make 5 copies of the last layer to add a pause in the GIF.
  • I scale the gif to 800 by 450.
  • Export as GIF by adding .gif to the file name. In pop-up window I select interlace (not sure why. Is that good?) I deselect comment. Select animation. Leave loop forever selected. Delay to 130. Select use delay for all frames. Leave last one unselected. Click export.
  • Done
Those are my skills. So now how do I add a layer to that with the ice?
90% of the world is religious, but somehow "love thy neighbour" became "fuck thy neighbours", if they don't agree with your point of view.

WTF happened?

be cause

  • Nilas ice
  • Posts: 2441
    • View Profile
  • Liked: 1012
  • Likes Given: 1034
Re: Creating Animated GIFs
« Reply #119 on: August 12, 2020, 10:34:34 AM »
BLUMENKRAFT SEEMS TO HAVE ALL THE NECESSARY SKILLS TO HELP YOU .. B.C.
Conflict is the root of all evil , for being blind it does not see whom it attacks . Yet it always attacks the Son Of God , and the Son of God is you .

oren

  • First-year ice
  • Posts: 9805
    • View Profile
  • Liked: 3584
  • Likes Given: 3922
Re: Creating Animated GIFs
« Reply #120 on: March 08, 2021, 02:16:31 PM »
A version of this may have been posted upthread, but still worth repeating. Cross-posting from Test Space.

cs2smos-piomas-ascat-jan-feb

Very handy uniquorn. How do you go about enhancing the ASCAT imagery?

A-Team does a better job but here is my method:

1. Download, install and open Fiji (ImageJ with plug-ins)
2. Drag the ascat files into the Fiji console. (start with a small selection, say, 5 days)
3. From the Image menu select Stacks->Images to Stack
4. Click the rectangle or ellipse button, select area of interest then from the Image menu select Crop.
5. From the Image menu select Adjust->Brightness/Contrast. Scroll through the images to view their histograms.
6. In the B&C console I increase the minimum to 41, in winter this doesn't lose too much information. Apply to all slices.
7. From the Image menu select Stack->Label, click the Preview checkbox and play with the numbers.
8. From the Image menu select Stacks->Make Montage. Set Scale Factor to 1 and click OK
9. From the Process menu select Enhance Local Contrast (CLAHE). I use 127,256,5.3 (For me this is usually just below 'too blocky' but A-Team prefers lower. Play with the numbers.
10. From the Image menu select Stacks->Tools->Montage to Stack and click OK.
11. From the Image menu select Stacks->Animation->Animation Options and choose a speed.
12. From the File menu select Save As->Gif

ImageJ has very few 'undo' options and it's easy to lose a lot of changes. Image->Duplicate is your friend. :)

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #121 on: April 29, 2021, 12:43:13 PM »
Here's a look at some of the regional sea ice changes over the last 6 days
Nicely put together BFTV, but why use a transition when you have all the data? Most of the drift detail is lost and it uses more frames.

uniquorn

  • First-year ice
  • Posts: 5117
    • View Profile
  • Liked: 2163
  • Likes Given: 388
Re: Creating Animated GIFs
« Reply #122 on: April 10, 2022, 08:07:49 PM »
Uni, if you feel inclined I'd really like to see something like that centered on the ice mass say @84n/180 to study for a while, so maybe a larger file. I want to see where the ice expands from and how it moves both as a body and by the exits perhaps in data heavy?
temp post.

Not really into requests (asif gets nearly everything I want to look at) but since it's already there...

Instructions are up thread, this was done using
6. In the B&C console I increase the minimum to 41, in winter this doesn't lose too much information. Apply to all slices.
9. From the Process menu select Enhance Local Contrast (CLAHE). I use 127,256,3.7
The avi was made using default jpeg quality 90/100 so also some loss there
didn't tidy up the file names...
looks like I forgot to change image type from 8bit to rgb too but it only affects the label.

.avi can be dragged into imagej as a virtual stack, duplicate the stack to make changes.
default ascat size scales well up to 2.5.
« Last Edit: April 10, 2022, 08:15:07 PM by uniquorn »