I am dealing with nonstandard binary data formats, which is one reason I
used od in the first place. The other reason for od is the data display in
several formats simultaneously, which has been very helpful at diagnosing
buggy output (e.g. byte swaps, accidental sign extension ...). I considered
writing a "few lines" of code, which I may end up doing (as in your python
example), but all of the formatting done by od takes many many lines of code
(from examining the source).   I am almost certain this has been done
before, but my Internet searches have turned up nothing.  20 years ago this
kind of program might have been interesting.

Hmm ... while writing, the following occurred to me.

Take a few lines of python code, and call them getRect. Then

$ cat image.data | ./getRect $base $span $stride $count | od -t x2 -t u2 -t
x1

I think that just might do the trick. It won't look like a plot, but it will
select a hundred pixels worth of data out of millions.

Thanks all for the suggestions.

Mat

On Wed, Jul 28, 2010 at 9:26 PM, Andrew Beyer <[email protected]>wrote:

> For transformations on images in some standard format, ImageMagick is
> often a good bet. If you are dealing with weird formats or arbitrary
> binary files, pipes are your friend...just filter the specific chunk
> of a byte stream you want to view and pipe that to od. You can do a
> one-liner (or maybe a few lines, depending on the verbosity your
> language of choice) in some scripting language to grab a "rectangular"
> section and output that to stdout. That way your "selection" logic is
> completely decoupled from od, so there's no need for extra features
> added to it.
>
> Given base, span, stride, and count, the python for a rectangle of
> bytes would be something like:
> chain([bytes.__getslice__(*row) for row in [(start, start+span) for
> start in [base+offset for offset in [stride*row for row in
> range(count)]]]])
>
>

Reply via email to