Page 1 of 1

Substituting colors in earth image, with reference image

Posted: 2013-12-10T05:44:40-07:00
by cefn
Hi all, I'm a long-time incompetent user of Imagemagick for simple operations, but first-time poster here on the forum as I'm trying something a bit complex manipulating satellite images to change their colors.

If anyone can describe the details of a credible approach to tackle what I want (using the right names for imagemagick operations), then I can have a go at figuring out the corresponding command line. Equally, if experts looking at the images reckon it's impossible to separate these colors sensibly, then I'll know to give up.

The project is to generate nice daily images of the earth from computer-generated globes rendered from geostationary satellites. The problem is that the pseudo-colors in the source images are a bit unnatural compared to people's expectations of maps (e.g. the sea is black, some of the clouds are a kind of light-blue). I need to be able to get the sea blue, and the clouds white, without visibly destroying any of the major continents! The colors of the land areas seem fine, and I'd like to preserve these. These will be printed fairly small for the project - which shows 5 years of globes, so the finished version will be forgiving of small errors.

You can see examples of the source images available at...
http://www.sat.dundee.ac.uk/geobrowse/g ... &slot=1200
I'm working with the 'Small' 'Colour' images available there.

I'm having trouble identifying what operations are available within Imagemagick to do this work effectively, and it's made more complex by a kind of differential reflection of light across the globe depending on the angle of incidence of the sun (e.g. the ocean in the centre of the globe is fairly reflective of the sun behind the satellite, whilst the edges of the globe are experiencing dawn or dusk and therefore brightness of the surface trails off).

I've had reasonable success using a Gimp select-by-color, then a color map operation, with the first being a color selection with a threshold by value (detecting the dark black pixels of the sea) then color mapping these selected areas to sea-blue, and the second being a color selection with a threshold by hue (detecting the light blue color), then color mapping these selected areas to cloud-white. You can see the results of the GIMP operations at http://cefn.com/gis/globe/

At the present time, something a bit like...
convert 2008_12_10_1200_MSG2_16_S4.png -fuzz 10% -fill blue -opaque "#030706" -fuzz 32% -fill white -opaque "#7cfffa" -fuzz 10% -fill '#BBBBBB' -opaque "#7d8091" out.png
...is close to the preferred result but there are areas (such as the direct reflection of the sun below the satellite) which are consistently incorrect and I can't figure out how to separate them using imagemagick operations. You can see this issue withing the images manipulated manually with GIMP too ( http://cefn.com/gis/globe/ ) at the centre of the globe, there's always a mid-grey blob, and towards the edges, there is also an increasing greyness. Changing the values to eliminate the central grey blob tends to also remove the Balkans and other countries towards the edge of the globe which are similar in light level.

I've attempted to understand some of Fred's scripts like those referenced at viewtopic.php?t=24052 but I'm having trouble figuring out how to do some operations within hue (picking out the blue clouds), and others within saturation (e.g. continents are colored, sea is black). There's something fundamental I'm missing about how these operations should be chained to create "greyscale" masks and then recombined. It may be that no correct series of operations is possible so I'll be led by people's suggestions on this.

Thanks for any ideas.

Re: Substituting colors in earth image, with reference image

Posted: 2013-12-10T07:57:53-07:00
by snibgo
cefn wrote:You can see examples of the source images available at...
http://www.sat.dundee.ac.uk/geobrowse/g ... &slot=1200
That site needs a username and password. Please put them somewhere that doesn't.

The problem sounds solvable, provided we can identify the pixels that need changing. If they have colours (hue or saturation or lightness or some combination) different to other pixels, that makes the job easier.

Re: Substituting colors in earth image, with reference image

Posted: 2013-12-10T08:19:19-07:00
by snibgo
Looking at your before and after Gimp images, a couple of immediate thoughts:

1. You are doing binary changes; each pixel is either changed to the new colour or it isn't. For pseudo-photographs such as these the effect is usually horrible. A better approach is to use masks as these can give degrees of change. A pixel can be changed anywhere between 0% (no change) to 100% (entirely changed to the new colour). See "-composite" when using a third image as a mask, or "-compose CopyOpacity" to copy a mask to the alpha channel of an image. The trick is then to make a good mask for each of the changes you want.

2. I think the conditions for the required changes are different at the centre, to the mid-radius, to the circumference. So I'd be inclined to work out three sets of conditions. The masks can then fade at the borders between the three areas, so the boundaries won't be visible.

Re: Substituting colors in earth image, with reference image

Posted: 2013-12-10T09:18:04-07:00
by snibgo
Another thought: your orig.png has clearly at some stage in its life been through some lossy compression, probably JPEG. If you can get hold of better images, the results will be better.