Reading txt files

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Reading txt files

Post 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.
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: Reading txt files

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

Re: Reading txt files

Post 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.)
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: Reading txt files

Post by fmw42 »

One way might be to modify sparse-color to write only rgb values in place of colornames.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Reading txt files

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Reading txt files

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

Re: Reading txt files

Post 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.
Last edited by snibgo on 2014-02-06T16:56:59-07:00, edited 1 time in total.
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: Reading txt files

Post by fmw42 »

there is an alternate formula --- std = sqrt(variance). This can be expressed as

std = sqrt ( ave(x^2) - (ave(x))^2 )
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Reading txt files

Post by snibgo »

Done. Rather than distract this thread, I've posted at viewtopic.php?f=22&t=24945
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Reading txt files

Post 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.
Post Reply