Page 2 of 2

Re: Rename image according to mean value

Posted: 2010-08-11T21:43:36-07:00
by anthony
At one point (for a little while) -set option:size worked! But it stopped recently. It was never offical, which is why I never relied on it.

Here was an example that use to work...

Code: Select all

  convert test.png -set option:size '%[fx:w]x%[fx:h]' +delete \
            xc:Orange color_set_size.gif
For this type of thing to work many more image structure settings will need to be converted to either
  • properties -set {prosperity} {value} which are attached to specific individual images
  • artifacts -set option:{artifact} {value} or -define {artifact}={value} which are global settings.
See verbose -identify or info: output whcih will list those settings.

NOTE: -define does NOT make use of 'percent escapes' Whcih is why I perfer to use -set method of settign artifacts, for example -set option:compose:args and -set option:distort:viewport

I would like to see more use of percent escapes in setting and operation arguments, such as I added to -distort and -sparse-color. In a re-write of "convert" I would make percent escapes very much more 'global' in use.

NOTE -set filename:{name} {value} is an in individual image property containing a colon in the property name. check it for yourself with info:

All thsi was being covered in Basics setion
http://www.imagemagick.org/Usage/basics/#attributes
But it needs a complete re-write from scratch!

Anyone like to have a go?

Re: Rename image according to mean value

Posted: 2010-08-11T21:54:41-07:00
by fmw42
The wink was because I knew it was hard and probably not going to happen in IM 6. I think it should be something in your list for IM 7.

Re: Rename image according to mean value

Posted: 2010-08-12T07:03:38-07:00
by forumware
Don't know if i should start a new thread but i'm puzzled and a little inexperienced.

The script that you gave FMW converts to grayscale and finds the "mean % of gray" and adds to the filename. But if I open one of these images in photoshop and check the histogram tab, the mean values are different.

I've been using this page as reference: http://kb2.adobe.com/cps/315/315207.html that mentions how to convert levels to % and backwards. I'm plugging the number from photoshop but nothing is matching. Any iput please?

Level = 256 - [(256)(P)/100]
IM %: 11.2288
Calculated level: 227.254272

Percentage = .390625(256 - L)
photoshop mean: 28.64
Calculated %: 88.8125

Re: Rename image according to mean value

Posted: 2010-08-12T11:24:37-07:00
by fmw42
One of my test images had channel stats of (identify -verbose imagefile)

Channel statistics:
Red:
min: 83 (0.32549)
max: 200 (0.784314)
mean: 152.391 (0.597613)
standard deviation: 20.0871 (0.0787731)
kurtosis: 13929.6
skewness: -0.367616
Green:
min: 38 (0.14902)
max: 155 (0.607843)
mean: 108.123 (0.424011)
standard deviation: 20.3941 (0.0799768)
kurtosis: 3489.21
skewness: -0.372234
Blue:
min: 9 (0.0352941)
max: 122 (0.478431)
mean: 76.9962 (0.301946)
standard deviation: 18.9897 (0.0744694)
kurtosis: 1271.66
skewness: -0.40976

After processing:

Channel statistics:
Gray:
min: 48 (0.188235)
max: 165 (0.647059)
mean: 117.784 (0.4619)
standard deviation: 20.1082 (0.0788556)
kurtosis: 5111.34
skewness: -0.384315


You can use mean 117.784/255=.4619 (as it is an 8-bit image) then multiply by 100 and you get 46.19%. the image had 46.2002% appended, but this is just calculation precision. To 3 sign figures, it is 46.2%

Or you can always use the mean value in parenthesis (which is always in the range of 0 to 1) and what fx calculates and reports and just multiply by 100 to get 46.19%

I presumed you wanted the resulting image to be converted to grayscale. If not, then ammend the script as


cd brcorners2
filearray=(`ls | grep '.jpg'`)
num=${#filearray[*])}
echo $num
for ((i=0; i<$num; i++)); do
inname=`convert ${filearray[$i]} -format "%t" info:`
meanval=`convert ${filearray[$i]} -colorspace gray -format "%[fx:100*mean]%" info:`
convert ${filearray[$i]} ${inname}_${meanval}.jpg
done


And your output will still be the same RGB color as the input (although it has been read, decompressed, recompressed and written out as it is jpg, so will be slightly different due to the decompression and recompression likely with different compression values. You cannot avoid that in IM). But only the overall graylevel of the color image will be appended. The image will still be RGB color.

If you want to avoid the compression issue, then you have to use the filesystem to rename the files.

I have no idea what you are asking about Photoshop.