Page 1 of 1

limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-29T18:01:32-07:00
by josephaaroncampbell
hello!

Is there a way to control the black level when using -compose Divide -composite to remove a vignette from an image?

usage link for vignette removal:
http://www.imagemagick.org/Usage/photos/#vignettation

my actual single line of code to convert the image is as follows:

Code: Select all

convert -quiet flatfield.tiff !name!!ext! -compose Divide -composite -density !dpi! -units pixelsPerInch -depth 8 -colorspace gray -negate +level 5%%,95%%,1.0 -gravity north -chop 0x!chopped! -rotate 180  -gravity south -splice 0x!addPixels! !namePfx!!nameNumber!.tif
(the '!words!' in the code are variables passed down through the batch file)

i have tried replacing -compose Divide -composite with the FX operation -fx '(u/v)*v.p{w/2,h/2}' but this crashes the batch file as soon as it starts.

My goal is to limit how dark the black levels become in the final output. Which is why +level 5%%, 95%%,1.0 is present in the convert code..but the -compose method of removing the vignette darkens too much. Is there a way to control this during the actual Divide operation?

Thanks!

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-29T18:55:22-07:00
by fmw42
Perhaps you should provide links to your two input images and your result image. Also what version of IM are you using?

Off the top of my head and not seeing your images, if your result is too dark, then just darken the denominator image using parenthesis processing and -evaluate multiply X%, where X is less than 100%

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-29T19:55:40-07:00
by josephaaroncampbell
Thank You for answering fmw42! I will provide a link tomorrow when i have access to the files again.

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-30T01:35:00-07:00
by snibgo
josephaaroncampbell wrote:My goal is to limit how dark the black levels become in the final output. Which is why +level 5%%, 95%%,1.0 is present in the convert code.
"+level" adjusts all the values, so they all fall in the range 5% to 95%. Or you could use 5% to 100% if you wanted. An input pixel at 25% will become slghtly lighter.

Perhaps you want to ensure that values below 5% become 5%, while leaving other value unchanged. For that, use "-evaluate Max 5%".

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-30T08:13:26-07:00
by josephaaroncampbell
Thank You for your responses. I've read about -evaluate before. I have tried editing the file used for the vignette correction and know i can change the results that way, but want to know if there is a better way. I will research evaluate again and try it out. In the mean time here is a link to the source images and batch files:

https://drive.google.com/open?id=0BzGl- ... Uc5N3JSclE

It contains some example raw files as well as my batch files for the project I am working on. You will also find a jpeg called 'goalOutput' which shows the density i am trying to achieve. As well as a jpeg called 'currentOutput' that shows what the Divide method is currently doing to the image.

I am digitizing glass plate negatives and I need there to be some kind of density or value seperation between the background and the glass. The photos will hopefully help illustrate this.

The hierarchy is as follows :

Parent Folder
-output folder :final tiff is moved here
-raw folder :raw files are moved here after edited
-source folder :incoming images from camera go here
-flatfield.tiff
-target.tif
-hotfolder.bat
-setup.bat
-flatfield.bat
-flatfield.cr2
-output.txt
-source.txt

The batch files are:

flatfield.bat : as long as there is a flatfield.cr2 file in the same folder it will create the flatfield correction tiff used in the main batch file using dcraw

setup.bat : creates the needed folders and files used by the main script ( folder 'raw', folder 'output', folder 'source', file 'output.txt', and 'source.txt')

hotfolder.bat : continuously checks for new cr2 files being dropped into the 'source' folder. Or they can just be dropped in to test the script.

The 'Source' folder needs to contain the 'target.tif' and the 'flatfield.tif' before starting the hotfolder batchfile.

*one last note. the main batch file 'hotfolder.bat' also calles ExifTool to pull the file name from the metadata of the raw file and placing it as a keyword of the output tiff.

If you have any questions please let me know. Sorry to dump a lot of info. And i really love imageMagick because of all of you. Thank you for your help. Im hoping to release the final workflow and files on here when i believe this is ready.

Thanks!

ImageMagick version 6.9.2-3 Q16 x64 2015-09-19
Windows 10

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-30T08:48:46-07:00
by snibgo
Sounds interesting. The link says "You need permission", so I clicked on a button that said it would ask you to give me permission.

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-30T13:06:24-07:00
by josephaaroncampbell
Sorry about that. Here instead is a dropbox link to the files zipped up. this shouldn't have issues. Thanks!

https://www.dropbox.com/s/0esz6dte5jdcn ... 0.zip?dl=0

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-09-30T15:06:41-07:00
by snibgo
flatfield.bat uses dcraw "-d", so this doesn't de-Bayer the image. But there is variation of hue across even the flatfield image, as well as _MGL0112.CR2 (because silver and the glass absorb different colours). So you should de-Bayer somewhere.

The camera makes a nominal 16 bits/channel. As you don't use dcraw "-6", you are throwing half of these away. Even if you only want 8 bits in the final result, don't throw them away before you need to.

The thumbnails in the CR2 files are slightly smaller than the raw images. You seem to use the raw image from flatfield, but thumbnails from the others. I suggest you use thumbnails from both, or raw from both.

The "divide" technique assumes the image is darker than the flatfield. Where it is lighter, clipping will occur. _MGL0112.CR2 is lighter than the flatfield, but only outside the good part of the image, so you may not care.

So, I here is a Windows BAT script. The programs are in my %IM% directory.

Code: Select all

%IM%dcraw -T -6 -O x.tiff _MGL0112.CR2

%IM%dcraw -T -6 -O f.tiff flatfield.CR2

for /F "usebackq" %%L in (`%IM%convert ^
  f.tiff ^
  ^( x.tiff -evaluate Multiply 0.9 ^) ^
  -compose Divide -composite -negate -rotate 180 -colorspace Gray ^
  +write d.tiff ^
  -gravity Center ^
  -crop 50%%x50%%+0+0 +repage ^
  -format "MIN=%%[fx:100*minima]\nMAX=%%[fx:100*maxima]" ^
  info:`) do set %%L

echo MIN=%MIN% MAX=%MAX%

%IM%convert d.tiff -level %MIN%%%,%MAX%%% dl.tiff
This makes x.tiff (the photograph) and f.tiff (the flatfield). I multiply x.tiff by 0.9 to get it (roughly) darker than the flatfield, then divide etc and write to d.png.

d.png is good. It is black where there is no glass plate, and nearly white where the silver is most dense. But the photographed shadows are somewhat light. I crop the central 50% is the image and find the darkest and lightest percentages. They are 17.1% and 94.3%. So I do a second convert that levels to those percentages. The unsilvered parts of the glass plate are now black. I think this shows the image better.

I don't convert to 8 bits at all, or use a lossy format such as JPG. But you might want 8-bit JPG as the final output, if you want.

Re: limit black/white levels when using -compose Divide -composite?

Posted: 2015-10-05T06:06:25-07:00
by josephaaroncampbell
This was incredibly useful. Your explanation has helped a lot. Im still working on a final solution and running some tests but will update when I can.
Thank You!