Fixing Carpet Bombing To Black from Perfectly Clear?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
BrianP007
Posts: 49
Joined: 2013-12-13T09:54:14-07:00
Authentication code: 6789

Fixing Carpet Bombing To Black from Perfectly Clear?

Post by BrianP007 »

Hi,
I have a new wizbang piece of image software, Perfectly Clear. The promise of "1 mouse click to instant perfection" has instead badly damaged a large number of my images before I realized what it was doing. The first thing it apparently does is to take the darkest few percent of all pixels and carpet bomb them to near perfect black. It looks like somebody redacted my images with a black magick marker.

Athentech tech support does not view crushing dark areas to pure black as a problem and has not suggested methods to prevent or fix this destructive defect. I like some of the software's effects on color separation and sky treatment so I have not returned it.

The manual fix to roll back the blackening is to:
1) open the vitiated file in Photohsop
2) duplicate layer
3) open backup, pre-damage version
4) select all, copy
5) return to the corrupted image, paste the old image to a new layer and move it below the degraded copy
6) in the damaged image, select color range, fuzziness=~16, range=100%, check localized color clusters and click on a BLACK spot
7) select modify -> expand(3), feather(2)
8) delete (clear) to erase the denigrated, "carpet bombed to black" areas which fall through to the original
9) flatten, save

This eliminates the carbonized areas and has a nice, smooth transition because of the feathering. But it takes a few minutes of manual labor per pic and some impetuous cowboy playing with his new toy (WSRN) mangled hundreds before inspecting the dark areas for irreparable damage. When printed, the damage appears dramatically worse than on the screen.

I can't figure out a Photoshop action to automate this because you have to pick a black area with the color picker.

In IM, I tried a similar fix and got fairly good results except that the extirpation sometimes leaves a noticeable banding. Here is my IM attempt:
# Convert the black to transparent with a fuzz factor in the burnt image and save as an RGBA with an Alpha channel.
convert nb-2013.0830-169664.p17.jpg -fuzz 7% -channel RGBA -fill none -opaque black nb-2013.0830-169664.p17.rgba.tif
# Add an alpha channel to the saved Original (thank goodness for backups!)
convert nb-2013.0830-169664.p17.o.jpg -alpha on nb-2013.0830-169664.p17.rgba.o.tif
# Superimpose the cutout burnt version over the original so the sullied, transparent sections fall through to the original
composite nb-2013.0830-169664.p17.rgba.tif nb-2013.0830-169664.p17.rgba.o.tif nb-2013.0830-169664.p17.rgba.sup.tif

I also tried the "Feathering Shapes using Distance" trick to try to get the Photoshop select->modify->feather effect. It took forever on 90 Mpix panorama and did not make that much difference.
convert nb-2013.0830-169664.p17.jpg -fuzz 7% -channel RGBA -fill none -opaque black -virtual-pixel transparent -morphology Distance Euclidean:4,3! nb-2013.0830-169664.p17.rgba2.tif

I can't figure out how to add images to illustrate the before vs. after crushing of darks to black.

Any pointer appreciated,

Brian
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by fmw42 »

You have to post them to some place like dropbox.com and then put the URL here. This forum does not allow uploading images.

What platform are you using and what version of IM? That is always a good thing to provide when asking questions on this forum.

You might try my autotone (or autotone2) script on your original images rather than Perfectly Clear, if you are using Linux/MacOSX or Windows with Cygwin.

You might also be interested in an old study I did regarding Perfectly Clear at http://www.fmwconcepts.com/misc_tests/P ... index.html, however it does no include my autotone scripts, which were created after that study.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by snibgo »

You can upload image files to somewhere like dropbox.com and paste the URLs here.

As a general approach to restoring the blacks, you might try something like this (Windows BAT syntax):

Code: Select all

convert ^
  original.tiff ^
  bad_black.tiff ^
  ( +clone 0 -colorspace Gray -level 0,5%% ^
    -write mask.tiff ^
  ) ^
  -composite ^
  out.tiff
"-write mask.tiff" isn't needed, but you can look at mask.tiff to see what is happening. Where this is black, you get pixels from original.tiff. Where it is white, you get pixels from bad_black.tiff. The effect blends between the two. Adjust the 5% to suit.
snibgo's IM pages: im.snibgo.com
BrianP007
Posts: 49
Joined: 2013-12-13T09:54:14-07:00
Authentication code: 6789

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by BrianP007 »

fmw42 wrote:You have to post them to some place like dropbox.com and then put the URL here. This forum does not allow uploading images.

What platform are you using and what version of IM? That is always a good thing to provide when asking questions on this forum.

You might try my autotone (or autotone2) script on your original images rather than Perfectly Clear, if you are using Linux/MacOSX or Windows with Cygwin.

You might also be interested in an old study I did regarding Perfectly Clear at http://www.fmwconcepts.com/misc_tests/P ... index.html, however it does no include my autotone scripts, which were created after that study.
=================
Fred,
Sorry I neglected to mention that I am running win7/64 (need photoshop)
ImageMagick 6.8.9-2 Q16 x64 2014-05-27\
uname='Win32 strawberry-perl 5.18.2.2 #1 Tue Apr 15 14:36:23 2014 x64'

I just have the cygwin linux tools (.EXEs) in my path, but not the whole cygwin. It has never been even close to right and has usually mucked up my system, needing copious debugging. A virtual machine has always been the preferred way to run real Linux side by side with the evil os. I don’t have one running on this workstation so I can’t run your Autotone2 bash script.

I did checkout your analysis of perfectly clear vs. other toning products. It would be informative to see your Autotones thrown into the mix.

PerlMagick runs very well on winders. I peeked at the bash guts of Autotone2. It looks like quite a few convert calls with intermediate file results. I wonder what difference keeping everything in memory as IM objects and using Perl’s incomparable data structures (hashes of hashes of arrays of references, ...) vs cygwin/bash/system_calls/file_system_storage would make.

I would be willing to help port some part, say the white balance section, to Perl as a test of concept. Interested?

Brian
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by fmw42 »

I am not sure autotone2 is as good as I first thought, though it does pretty well. Unfortunately, I do not code Perl/Perlmagick or any other API. But thanks for the suggestion. When I get some time, I will try to add autotone and autotone2 to comparison page. If you want to send me a couple of your images, I would certainly be willing to run them through autotone and autotone2 for you.

As for Cygwin, see http://im.snibgo.com/cygwin.htm
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by snibgo »

Fred's autotone and autotone2 run successfully under Cygwin on my Windows laptop. They need bash, of course, and various other Unix tools.
BrianP007 wrote:I peeked at the bash guts of Autotone2. It looks like quite a few convert calls with intermediate file results. I wonder what difference keeping everything in memory as IM objects and using Perl’s incomparable data structures (hashes of hashes of arrays of references, ...) vs cygwin/bash/system_calls/file_system_storage would make.
My preference, these days, is for a script to build and run a single long command, rather than run multiple converts. This reduces disk I/O. Of course, it doesn't work when the nature of one process depends on a previous result. For debugging purposes, scripts can insert "+write xx.tiff" as required into the command.

However, when developing IM skills, it is far easier to run multiple converts, and keep each one simple.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixing Carpet Bombing To Black from Perfectly Clear?

Post by fmw42 »

snibgo wrote:My preference, these days, is for a script to build and run a single long command, rather than run multiple converts. This reduces disk I/O. Of course, it doesn't work when the nature of one process depends on a previous result
When a script is simple and there are not a lot of argument, then I, too, try to keep it to one command line. But when some arguments are used or not used and affect the need to remove or use long commands, it is hard to build that into one command line. So for example, autotone has a number of options to perform or not perform certain tasks (auto brighten/contrast, sharpen, color balance by different methods and remove noise), it is hard to make this into one single long command line, when you want to give the user options to use or not use these features. It can be done, but takes some tricks. If someone needs a simple set of these options, I can usually write a custom script to do so with one command line and few other command lines to make computations or variables. This of course is harder in IM 6 than it will be in IM 7, due to the lack of in-line computations in most of IM 6.
Post Reply