Page 1 of 1

How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T11:55:01-07:00
by Flesh
Currently I am running the below command to set the format to png and make canvas 300 px larger on both sides of image, and to also remove the Black Background by setting it transparent, I found out that synchronize did not do what I wanted, but I still use it, what I need is a way that if this command does not complete, as it did last night when power went off longer then my battery backup lasted, that I do not have to start over, seeing how I am using *.jpg, if there is no way to do that, maybe I can call it from a bash script, but this is all in preparation for another operation, I want to extend the sides if the Corona of the Sun in image below, makes a hard edge as seen here, note that the top and bottom Corona are Minimal and do not always exist, and the side to side Corona also does not make a hard edge all the time, just parts of the year, and it might be on one side or the other or both, so really what I want is a Smudge of 10 px out to 300 px tapering as the example dose, and I was wondering if I can do this in one command, this takes a long time to render this many images, sorry if I give too much info or not enough, better too much then not enough is my thought.

Code: Select all

mogrify -synchronize -alpha set -transparent black -background transparent -gravity center -extent 4696x4096 -format png -path ../2016-png *.jpg
I have an Animation of the Sun Series, as you can see, the Hard Edge does not look that good:
see https://www.youtube.com/playlist?list=P ... fvNkVm3m6c

As you can see from the Image below:

Image

The Corona of the Sun has a hard edge on both sides sometime, sometimes they extend up and down, but not much, and the few times this did happen I fixed them by hand, but the side ones do not look good and there are too many to edit by hand.

What I want to do is soften the hard edge so it looks more like this:

Image

I just did a fast Smudge by hand in GIMP, this was originally a Blender question, and then a GIMP question, still looking for a better way to do this.
Blender Thread
https://blender.stackexchange.com/quest ... e-of-image
GIMP Thread
https://www.gimp-forum.net/Thread-How-t ... e-of-image

My Original images are Public Domain images of the Sun from NASA AIA 193 https://sdo.gsfc.nasa.gov/data/aiahmi/ in 4096x4096 format jpg, just pick one with a Corona on but sides, and an Environment 360 degree image texture map of the Stars as background using Blender to alpha over the Sun, that is only shown for an Example and is not used in conversion, and I write and preform my own music.

There are over 33,333 images for one Year and I have over 6 years of images that I am working with, that is over 200,000 images, so I can not do this by hand in my lifetime since I am dying of Cancer my time is limited, I am old and have Arthritis as well, so it would be a very painful way to go out, and I might not finish it, so why start, but I wanted to finish this series, and go back and do years before the series started, which is 2010, so people can view the sun over a decade, but the hard edge looks bad, and I know there is a way to fix this, but I am not good enough at blender or Gimp to figure it out, I think I ask this question once a year, and try to figure out how to fix it, so far I end up not fixing it. My guess is that I need to write a script that takes the edges of the images and blurs or smudges it side ways in an oval shape, but I know even less about it when it comes to automating edits in gimp, then I do about Blender, not even sure it can be done, no idea how to do that, anyone have any ideas?

I originally did the video in 1080, now I want to render it in 2160 AKA 4K, since the originals are larger then the 3840, it should look good at 4k, but I want to fix this issue since it will take a long time to render all these images in Blender, and I want it to look Natural or Real, so even if all I can do is blur the hard edge, that would be an improvement.

Update: Running Linux Manjaro (Arch Linux Clone) with latest version of IM.

Thanks

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T13:03:42-07:00
by snibgo
Please provide your input images: the sun, and the stars.

Please tell us what version of IM you use, on what platform.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T13:52:16-07:00
by Flesh
This is the original image like shown above, in 4096 format

Image

Like I said the link for the images are at NASA, just pick one that has a Corona on both sides, but its just as easy to post one, and I should have.

The Image of the Stars does not matter since its only shown for an example, and is an Environmental Image Texture Map, and not a real Image, its a 360 degree image of the Stars at Night, so it has to be in reference to a Camera angle, an is alpha'd over in blender to make the video.

I am running Manjaro an Arch LInux clone, so its a Rolling Release.

Version: ImageMagick 6.9.8-10 Q16 x86_64 2017-06-12

Thanks for the help, sorry I guess I did not give enough information after all, the version always helps.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T16:16:21-07:00
by fmw42
Here is one way in Unix IM syntax, though it is more of a rounding fill than a spread. I use +distort SRT with a no-op, but expand the window 300 pixel left and right using the viewport. Then I create a circle mask and apply the circle mask to the expanded (spread.png) image as a blur mask and then negate the mask, blur a little for anti-aliasing the hard edge and use it to mask out the excess blurred region to black. I have saved the spread.png and mask.png images just for show. So you can delete the +write XXX.png later. If you do not like a perfect circle. You can draw your own mask. I used a thresholded gradient to make the circle, though you could use -draw to draw a black circle in side a white background. Images are shown below. I resized your original to 25% for processing time and to demonstrate.

input:
Image

Code: Select all

infile="solar.png"
pad=300
declare `convert "$infile" -format "W=%w\nH=%h" info:`
wd=$((W+2*pad))
ht=$H
convert \( "$infile" -set option:distort:viewport "${wd}x${ht}-${pad}+0" -virtual-pixel mirror +distort SRT 0 +write spread.png \) \
\( -size ${wd}x${ht} -define gradient:extent=minimum radial-gradient:black-white -negate -threshold 0 -negate +write mask.png \) \
\( -clone 1 -negate \) \
\( -clone 0,1,1 -compose blur -define compose:args=100x0+0 -composite \) \
-delete 0-1 +swap -compose multiply -composite solar_proc.png
extended image:
Image

mask image:
Image

result image:
Image

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T16:27:22-07:00
by GeeMack
Flesh wrote: 2017-07-24T11:55:01-07:00The Corona of the Sun has a hard edge on both sides sometime, sometimes they extend up and down, but not much, and the few times this did happen I fixed them by hand, but the side ones do not look good and there are too many to edit by hand.

What I want to do is soften the hard edge so it looks more like this:
I've been processing SDO images since the very first data was acquired. Even with the 193 angstrom images and their normally soft edges, there are tens of thousands of them which will vary extremely. Flares at the limb obviously won't always be parallel to the equator or perpendicular to the tangent, so the best simulated extension of the corona will necessarily also simulate the angle of dispersion. If the adjustment isn't done gradually, they may look as bad as a simple sharp cut off.

I worked up a command that starts with a single 4096x4096 image, slices a piece off the left and right sides, stretches those pieces, and reattaches them. Then it does the same thing a few more times with a bit larger piece, stretching each step a little wider. The result is a graduated stretch from just outside the limb of the Sun to the finished width of 7282. That resizes down to 1280x720 for the 16:9 aspect video. Here is the sample command...

Code: Select all

convert SDO-AIA-193_2017-07-22_23-59-40.jpg \
   \( -clone 0 -gravity west -crop 400x4096+0+0 -resize 600x4096! \) \
   \( -clone 0 -gravity center -extent 3296x4096 \) \
   \( -clone 0 -gravity east -crop 400x4096+0+0 -resize 600x4096! \) \
   -delete 0 +append \
   \( -clone 0 -gravity west -crop 500x4096+0+0 -resize 800x4096! \) \
   \( -clone 0 -gravity center -extent 3496x4096 \) \
   \( -clone 0 -gravity east -crop 500x4096+0+0 -resize 800x4096! \) \
   -delete 0 +append \
   \( -clone 0 -gravity west -crop 600x4096+0+0 -resize 1000x4096! \) \
   \( -clone 0 -gravity center -extent 3896x4096 \) \
   \( -clone 0 -gravity east -crop 600x4096+0+0 -resize 1000x4096! \) \
   -delete 0 +append \
   \( -clone 0 -gravity west -crop 700x4096+0+0 -resize 1393x4096! \) \
   \( -clone 0 -gravity center -extent 4496x4096 \) \
   \( -clone 0 -gravity east -crop 700x4096+0+0 -resize 1393x4096! \) \
   -delete 0 +append -resize 1280x720 1280x720.png
Here's an example of the output using a 193Å filter image from 2017-07-22.

Image

The main concerns with something like this are the images that have much larger flares in areas other than the equator. The stretching may take on a slight over-up-over-up distortion.

A greater concern might be the time it takes to run this. It takes several seconds to run on a single original 4096 square level 1 image file, and might be simply impractical to run on several years worth of data. At the very least I would process the original images to 720x720 first, then rebuild that command so the numbers work on the smaller input files.

I am trying a couple other ideas, and fmw42 offered a good one above. I'll post sample commands of anything else I come up with.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T16:35:38-07:00
by fmw42
Using a somewhat elliptically shaped mask, might do better for my approach.

But GeeMack's result look great. A suggestion would be to do a depolar distort and then stretch/shift in the correct columns, then a reverse polar distort. That would give a radial direction to the flares or corona.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T18:18:43-07:00
by Flesh
Thanks, can you tell me if there is a way to continue this if the process gets interrupted, i.e. power outage, it takes days to convert this many files, and I do not want to start over every time.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T18:43:24-07:00
by fmw42
You would write a script loop over the command. It would loop over each image in some folder and process it. If it stops, those files are not lost. You just need to restart the script at the next image that was not processed.

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T22:15:56-07:00
by Flesh
Something like this:

Code: Select all

find . -type f -name "*.jpg" -print0 | sort -z | while IFS= read -r -d '' file; do
    BaseFileName="$(basename $file)";
    PngFile="${BaseFileName%.*}.png";
    echo "Working on ${Counter}";
    if [ ! -f "${Output_Folder}/${PngFile}" ]; then
        r=$(mogrify -synchronize -alpha set -transparent black -format png -path "${Output_Folder}" "$BaseFileName");
    fi
    ((Counter++));
done

Re: How to extend an Image from side to side softening the hard edge of image

Posted: 2017-07-24T22:40:17-07:00
by fmw42
Mogrify is OK for simple commands and to process a whole folder of images. But would not use mogrify. It is not as flexible if you are going to process my command or GeeMack's. I would use convert. Also read the input file before the rest apart from -synchronize and the output last.

But all you are doing is making the black transparent. Is that all you want? Using that will make the result a bit aliased.

Code: Select all

create output director
cd to input directory
list=`ls *.jpg`
count=0
for img in $list; do
name=`convert -ping "$img" -format "%t" info:`
convert -synchronize "$img" -alpha set -transparent black path2_output/${name}.png
count=$((count+1))
done
Add you validity tests if you want.