Page 1 of 1
Reading txt files
Posted: 2014-02-05T20:17:19-07:00
by snibgo
When writing txt: output, IM seems to use integers for Q8 data but percentages for Q16. Sadly, it can't read txt files that are in percentages.
For example:
Code: Select all
F:\web\im>c:\im\ImageMagick-6.8.8-Q16\convert xc:rgb(10%,20%,30%) ta.txt
F:\web\im>type ta.txt
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (10.0008%,20%,30.0008%) #199A33334CCD srgb(10.0008%,20%,30.0008%)
F:\web\im>c:\im\ImageMagick-6.8.8-Q16\convert ta.txt txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (100%,100%,100%) #FFFFFFFFFFFF white
v6.8.6 worked fine. The problem occurred at v6.8.7-0, and is still a problem at 6.8.8-0 (on Windows 8.1).
IM correctly reads 16-bit "txt:" files that are integers, but writes them out as percentages.
Re: Reading txt files
Posted: 2014-02-05T20:59:46-07:00
by fmw42
Before 6.8.7-0, the raw values were 16-bit integers for Q16 compile. I am not sure what it presented for Q32. I suspect the change was done to present easier to interpret 32-bit data, but that is just a guess.
I must admit, I never noticed that IM could not read the newer format txt: files when converting to other output formats, but I can confirm your bug on IM 6.8.8.4 Q16 Mac OSX Snow Leopard.
Also
convert ta.txt ta.png
incorrectly creates a single white pixel.
Re: Reading txt files
Posted: 2014-02-05T22:05:01-07:00
by snibgo
Thanks.
My workaround is to write txt: with v6.8.6, do my manipulations, then read it with current IM.
Ideally, I'd like to be able to specify whether I want writing as integers or percentages. But the main thing is to be able to read what was written.
(I'm doing this to find the standard deviation and other stats of masked pixels. I'm using the alpha channel as a boolean mask. Sparse-colour would be the obvious way except that it writes colour names etc so it isn't easy to read back in. The best way I've figured out so far is to write as "txt:", filter out what pixels I don't want, and write the others to a new "txt:" file with height=1. I'd welcome better ideas.)
Re: Reading txt files
Posted: 2014-02-05T22:12:55-07:00
by fmw42
One way might be to modify sparse-color to write only rgb values in place of colornames.
Re: Reading txt files
Posted: 2014-02-05T22:16:59-07:00
by fmw42
Have you tried IM 7? It is supposed to be able to use read masks, though I do not know how far that got implemented.
Re: Reading txt files
Posted: 2014-02-05T22:19:47-07:00
by fmw42
If you just want the mean, you can do that using my trick at
http://www.fmwconcepts.com/imagemagick/ ... shape_mean. I have not tried to work out std, though.
Re: Reading txt files
Posted: 2014-02-06T01:29:48-07:00
by snibgo
Hmm, thanks. Taking SD = sqrt[(u-mean)^2/n], it should be easy to do in IM.
EDIT: forgot to put in the ^2.
Re: Reading txt files
Posted: 2014-02-06T10:55:13-07:00
by fmw42
there is an alternate formula --- std = sqrt(variance). This can be expressed as
std = sqrt ( ave(x^2) - (ave(x))^2 )
Re: Reading txt files
Posted: 2014-02-06T16:57:25-07:00
by snibgo
Done. Rather than distract this thread, I've posted at
viewtopic.php?f=22&t=24945
Re: Reading txt files
Posted: 2014-02-07T04:01:50-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.8.8-5 Beta available by sometime tomorrow. Thanks.