<p>Finally caught a glimpse of the comet after a week of cloudy weather. Shot from the escarpment, with some of the downtown Hamilton in the foreground.
</p><p>HSS!
</p><p>Here is my technique for subtracting the foreground (sky glow) from sky photos near horizon (works for normal to telephoto lens range; doesn't work for wide angle lenses):
</p><p>1) Take the photo as RAW, process it as 16 bit color per channel, to preserve all the information
2) Open the photo in your image editor (GIMP, Photoshop etc), straighten the horizon, and erase to transparency all objects which are not sky glow - bright stars, comets, landscape. You end up with a "Swiss cheese" photo. Save it as a TIFF file with transparency enabled, say bg.tif .
3) Use a command line tool ImageMagick (Q16 version) to process bg.tif. Execute the following command:
</p><p>$ magick convert bg.tif -resize 1xH\! -resize WxH\! bg2.tif
</p><p>Substitute W with the width, and H with the height of the image bg.tif in pixels. The above command will effectively average out all the rows of pixels in bg.tif (but only for non-transparent pixels), creating a sky glow model for your photo.
4) Load bg2.tif back to your photo editor (where you still have your original photo, with the horizon straightened). Apply a bit of vertical motion blur (~20 pixels) to make the model smoother.
5) Make it as the second layer, with the first layer being your original photo with the horizon straightened. Choose Difference as the first layer option (so the second layer is subtracted from the first one). 
</p>
6) Voila - the sky glow is gone! You can now merge the two layers, and adjust the levels as needed, to bring out all the faint details.
<a rel="nofollow" class="external text" href="https://www.flickr.com/people/30041560@N03">SyamAstro (750,000 views - thank you!)</a>
<a rel="nofollow" class="external text" href="https://www.flickr.com/photos/syamastro/50128485178/">Comet Neowise over Hamilton, Canada</a>