Remove too dark photos from batch

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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove too dark photos from batch

Post by snibgo »

That's it. You just need the convert. With the arguments you have, it converts file1 to match the statistics of file2.

Code: Select all

convert file1.jpg -function Polynomial $gain,$bias out.jpg
snibgo's IM pages: im.snibgo.com
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Terrific! One step further.
Out of curiosity, what is the PS equivalent to this? If there is any?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove too dark photos from batch

Post by fmw42 »

I don't think PS has such a function that uses gain and bias as multiplier and addition. The closest I know is just contrast-brightness sliders.

You can also do this with -color-matric by adjusting the diagonal. In PS, that would be the channel mixer.

see
http://www.imagemagick.org/script/comma ... lor-matrix
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

The scripting is getting a bit cumbersome for me and I am thinking about trying imagemagick using another language. Took a look at python and wand but it does not seem to support many functions (though I gather you can work around it). Is it possible to recommend another language? I do not know any of the ones listed, so preferably easy to learn and with good support of IM.
Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove too dark photos from batch

Post by fmw42 »

My belief is that most of the other APIs are far behind in their functionality compared to the command line. The two that might have the most besides MagickCore (which is likely up to date) are probably Perlmagick or Magick.NET. But I do not use any of them. So one of the developers would likely need to comment.
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Ok, thanks. Also found this:
https://github.com/aheckmann/gm
But not getting anywhere with it
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Is it possible to do "identify" on the embedded preview of a dng.file? To speed up the process?
snibgo wrote:Shells are often bad at handling floating-point. Either use a calculator like bc, or do more calculation within IM, eg:

Code: Select all

identify -format "%[fx:mean>0.345?1:0]\n" filename
This returns 1 when the mean is greater than 0.345; otherwise it returns 0.

You may need to escape the ">".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove too dark photos from batch

Post by snibgo »

Yes, but you need to extract it first, eg:

Code: Select all

exiftool -Composite:PreviewImage -b myfile.dng >preview.jpg
snibgo's IM pages: im.snibgo.com
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Thanks!

Code: Select all

exiftool -b -PreviewImage -w _preview.jpg -ext dng .
in case someone googles here, the above worked for doing a batch in the same folder and naming them as the dng + _preview. It threw an error also: "Error: File format error - ./.__filename.dng" but the previews are available.
I am looking to sort out more images, got the very dark ones removed. Now I think I will prioritize the nice weather pictures. What would be a good way to distinguish between the attached photos? And maybe abit more subtle differences. Seems like the temperature is changing alot, maybe better than the standard deviation? Is compare the way to do it?
Niceweather
Notsonice
Last edited by salmen on 2016-04-15T11:09:20-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove too dark photos from batch

Post by snibgo »

Well, what is "nice weather"? To me, it is blue skies and high contrast. The hue of the sky won't change much, but the saturation will. Here I use the Chroma from HCL colorspace, on a scale of 0.0 to 1.0:

Code: Select all

f:\web\im>%IM%convert cons3.jpg -gravity North -crop x50%+0+0 +repage -colorspace HCL -format %[fx:mean.g] info:
0.254661

f:\web\im>%IM%convert cons4.jpg -gravity North -crop x50%+0+0 +repage -colorspace HCL -format %[fx:mean.g] info:
0.0418506
That's a very clear difference.

The standard deviation gives a measure of contrast. "-auto-gamma" makes the mean of both images 0.5.

Code: Select all

f:\web\im>%IM%convert cons3.jpg -gravity South -crop x50%+0+0 +repage -auto-gamma -format %[fx:standard_deviation] info:
0.146643

f:\web\im>%IM%convert cons4.jpg -gravity South -crop x50%+0+0 +repage -auto-gamma -format %[fx:standard_deviation] info:
0.0988983
The difference isn't so great, but it's probably enough to distinguish "nice" from "not nice".

Colour temperature can be measured as the ratio mean(red)/mean(blue):

Code: Select all

f:\web\im>%IM%convert cons3.jpg -gravity South -crop x50%+0+0 +repage -auto-gamma -format %[fx:mean.r/mean.b] info:
1.17196

f:\web\im>%IM%convert cons4.jpg -gravity South -crop x50%+0+0 +repage -auto-gamma -format %[fx:mean.r/mean.b] info:
1.00884
snibgo's IM pages: im.snibgo.com
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Makes sense, thought I'd give saturation a go but bash seems to hang from the following?

Code: Select all

chroma=$(convert "$file" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format %[fx:mean.g] info:)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove too dark photos from batch

Post by fmw42 »

chroma=$(convert "$file" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format %[fx:mean.g] info:)
In unix, the %[...] needs to be quoted. Try

Code: Select all

chroma=$(convert "$file" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format "%[fx:mean.g]" info:)
salmen
Posts: 20
Joined: 2016-04-07T12:52:48-07:00
Authentication code: 1151

Re: Remove too dark photos from batch

Post by salmen »

Thanks, lots of things to learn.. I am not getting anywhere with floats in bash. I can store the chroma, but not compare them

Code: Select all

refchroma=$(convert "$refimg" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format "%[fx:mean.g]" info:)
chroma=$(convert "$file" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format "%[fx:mean.g]" info:)
Then I would like to do something like diff=$(bc -l<< "$refchroma-$chroma"), but cant figure it out
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove too dark photos from batch

Post by snibgo »

You could do calcs in IM, eg:

Code: Select all

refchroma=$(convert "$refimg" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format "%[fx:mean.g]" info:)

diff=$(convert "$file" -gravity North -crop x50%+0+0 +repage -colorspace HCL -format "%[fx:$refchroma-mean.g]" info:)
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: Remove too dark photos from batch

Post by fmw42 »

diff=$(bc -l<< "$refchroma-$chroma"),
try

Code: Select all

diff=$(echo "scale=6; ($refchroma-$chroma)/1" | bc)
The divide by 1 seems to be needed (for me) to force floating point results, despite the scale=6.

or in IM

Code: Select all

diff=$(convert xc: -format "%[fx:$refchroma-$chroma]" info:)
Post Reply