Removing sky behind trees — GIMP/Photoshop NOT?

ML
Posted By
Martin Leese
Dec 5, 2007
Views
1634
Replies
8
Status
Closed
Charles Packer wrote:
Consider an RGB image of trees against
sky. I want to remove the sky, i.e. set
each sky pixel to 0,0,0. The fuzzy
selection methods available in GIMP and,
I assume, Photoshop, are manual and
impossibly tedious, especially when
there are multiple areas of sky enclosed
by branches, as in a winter scene.

An algorithm is needed. The intuitive
solution would appear to involve taking
a sample of sky pixels, plotting them in
RGB space, and finding a straight-line fit.
Pixels close to the line will be sky.
The fuzziness of the selection will be
controlled by choosing how far away from
the line to accept.

Don’t have a package to recommend to you,
but I don’t see where a straight line fit
comes in.

Typically, a simple classification algorithm
finds the centroid coordinates of the sample
sky pixels. Pixels close to this point in
RGB space are then sky. Alternatively, the
algorithm finds the bounding cuboid of the
sample sky pixels. All pixels inside the
cuboid are then sky.

A sophisticated classification algorithm
fits a multivariate (in this case 3-variable:
R, G, B) Gaussian distribution to the sample
sky pixels. (Imagine a ellipsoid with fuzzy
edges.) This is all standard stuff for
remote sensing packages, except that they
typically work with more than three bands.
Don’t know of any that are free, however.
Perhaps others do.


Regards,
Martin Leese
E-mail:
Web: http://members.tripod.com/martin_leese/

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

NP
Norman Peelman
Dec 6, 2007
Martin Leese wrote:
Charles Packer wrote:
Consider an RGB image of trees against
sky. I want to remove the sky, i.e. set
each sky pixel to 0,0,0. The fuzzy
selection methods available in GIMP and,
I assume, Photoshop, are manual and
impossibly tedious, especially when
there are multiple areas of sky enclosed
by branches, as in a winter scene.

An algorithm is needed. The intuitive
solution would appear to involve taking
a sample of sky pixels, plotting them in
RGB space, and finding a straight-line fit.
Pixels close to the line will be sky.
The fuzziness of the selection will be
controlled by choosing how far away from
the line to accept.

Select ‘By Color’ and adjusting the threshold doesn’t do this?

Norm
TN
Tom Nelson
Dec 6, 2007
You’re describing the Feather parameter of Photoshop’s selection tools. The problem of using physical distance for your fuzziness parameter is that the out of focus border around foreground objects involves color as well as distance. Assuming you’ve got a typical ugly near-white sky and want to change it to a darker blue, the apparent width of the fuzzy edge depends on how near the foreground object’s color is to the sky color as well as the width of the blur itself. Telephone wires look crisp because their color changes abruptly from black to near-white. Masses of foliage are closer to sky color and change more gradually.

In the above scenario, you are changing the brightness of the sky as you change its color. If you select the sky, you can presumably set a Feather to remove part of the wires’ fuzzy edges at the exact brightness of your new sky color. Such a Feather would be wrong for the foliage, giving it a bright halo.

Instead, the Color Range command in Photoshop is the algorithm you want. It allows you to set a range of colors as 100% selected and to also use a Fuzziness slider to set other colors as partially selected depending on how close in color they are to the selected colors. This gives a softer blend to the near-sky-color objects and a more abrupt one for objects that contrast with the sky. It doesn’t completely solve the brightness problem but it comes closer.

Tom Nelson
Tom Nelson Photography

Charles Packer wrote:
Consider an RGB image of trees against
sky. I want to remove the sky, i.e. set
each sky pixel to 0,0,0. The fuzzy
selection methods available in GIMP and,
I assume, Photoshop, are manual and
impossibly tedious, especially when
there are multiple areas of sky enclosed
by branches, as in a winter scene.

An algorithm is needed. The intuitive
solution would appear to involve taking
a sample of sky pixels, plotting them in
RGB space, and finding a straight-line fit.
Pixels close to the line will be sky.
The fuzziness of the selection will be
controlled by choosing how far away from
the line to accept.
ML
Martin Leese
Dec 7, 2007
Charles Packer wrote:

I’ve uploaded a small image, (not
gamma-corrected)
http://cpacker.org/a1.png
that I think shows why I need a line
rather than an ellipsoid.
….
When I used gnuplot to 3D-plot every
100th pixel of this image, they
fell along a shockingly straight line.

Any chance of also uploading an image of the
gnuplot.


Regards,
Martin Leese
E-mail:
Web: http://members.tripod.com/martin_leese/
P
perry1removethis
Dec 7, 2007
Martin Leese wrote:
Charles Packer wrote:
Consider an RGB image of trees against
sky. I want to remove the sky, i.e. set
each sky pixel to 0,0,0. The fuzzy
selection methods available in GIMP and,
I assume, Photoshop, are manual and
impossibly tedious, especially when
there are multiple areas of sky enclosed
by branches, as in a winter scene.

An algorithm is needed. The intuitive
solution would appear to involve taking
a sample of sky pixels, plotting them in
RGB space, and finding a straight-line fit.
Pixels close to the line will be sky.
The fuzziness of the selection will be
controlled by choosing how far away from
the line to accept.

Don’t have a package to recommend to you,
but I don’t see where a straight line fit
comes in.

Typically, a simple classification algorithm
finds the centroid coordinates of the sample
sky pixels. Pixels close to this point in
RGB space are then sky. Alternatively, the
algorithm finds the bounding cuboid of the
sample sky pixels. All pixels inside the
cuboid are then sky.

A sophisticated classification algorithm
fits a multivariate (in this case 3-variable:
R, G, B) Gaussian distribution to the sample
sky pixels. (Imagine a ellipsoid with fuzzy
edges.) This is all standard stuff for
remote sensing packages, except that they
typically work with more than three bands.
Don’t know of any that are free, however.
Perhaps others do.


Regards,
Martin Leese
E-mail:
Web: http://members.tripod.com/martin_leese/

You should try Mask Pro 4 a Photoshop plug-in, works a treat. Five minutes and you’re done.
ML
Martin Leese
Dec 7, 2007
Charles Packer wrote:

On Dec 6, 9:43 pm, Martin Leese
wrote:
Any chance of also uploading an image of the
gnuplot.

Look at http://cpacker.org/a1.gif
I would have expected an image of this
genre to to scatter about the RGB space
more. However, I have no previous
experience with these plots outside
of image processing textbooks.

Bands near to the visible are correlated,
and the visible bands highly so. I would
have expected the cigar shape to be fatter,
but a cigar is normal. Note that it will
only point towards the origin in the
absence of haze.

http://cpacker.org/aman.gif
shows a few manually selected sky and
and tree branch pixels from the region
of the image that will give me the most
trouble. Sky pixels are filled circles,
tree branch pixels are open circles.
The two groups of pixels are almost
collinear. So just using any one of red,
green or blue values to discriminate might be
as good as anything! It might be that I’ll
have to supplement any color-space
methodology with some kind of spatial
analysis.

Note that the two groups of pixels are mixed.
That is to say, the "sky" cluster and the
"tree" cluster overlap. This shows that if
you use only RGB values to classify the
pixels then some will inevitably end up in
the wrong class.

To improve on this you will need to use
information other than that contained in RGB
(or HSI, Lab, etc) space. My guess is that
this would get a lot more sophisticated than
you desire.


Regards,
Martin Leese
E-mail:
Web: http://members.tripod.com/martin_leese/
ML
Martin Leese
Dec 7, 2007
Martin Leese wrote:

Note that the two groups of pixels are mixed.
That is to say, the "sky" cluster and the
"tree" cluster overlap. This shows that if
you use only RGB values to classify the
pixels then some will inevitably end up in
the wrong class.

Forgot to mention that you classify this
image by chopping the cigar into two lumps.
Your only variables are where to chop, and
whether to leave a gap (containing
unclassified pixels) between the two lumps.


Regards,
Martin Leese
E-mail:
Web: http://members.tripod.com/martin_leese/
F
Fred
Dec 14, 2007
Look at your Channels-panel.
Pick the channel with the most contrast.
Duplicate that channel (important!)
Now tweak the grays with Levels.
Manually fix some areas.
CTRL- or CMD- click on the channel thumb to load the selection. Go back to your layers panel and add a mask.
Say: ‘Waw, I’m amazing!’

Good luck
K
KatWoman
Dec 16, 2007
"Fred" wrote in message
Look at your Channels-panel.
Pick the channel with the most contrast.
Duplicate that channel (important!)
Now tweak the grays with Levels.
Manually fix some areas.
CTRL- or CMD- click on the channel thumb to load the selection. Go back to your layers panel and add a mask.
Say: ‘Waw, I’m amazing!’

Good luck

that is an excellent method for difficult mask jobs
for more detail on it
Russell Brown has a great video
step by step

he uses the levels but tweaks it using dodge//burn
gives a very precise selection

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

Related Discussion Topics

Nice and short text about related topics in discussion sections