Setting an Image File Values

W

W. Watson

I have a 640x480 b/w bmp image file that can be converted to a dat file. I would like
to convert the value of each pixel that is below say 120 units to exactly 40 units.
I've never written a python program in my life. However, the manual for the image
application I'm looking at show the following line to create a mask.dat file of size
640x480 bytes with every value set to 40:
python -c "open('mask.dat','w').write(chr(40)*640*480)"
I suspect a program to do what I need is not much more complicated. Can someone
construct a program for me to do the job? It'll probably be the only python program I
ever need.

--
Wayne T. Watson (121.015 Deg. W, 39.262 Deg. N, 2,701 feet, Nevada City, CA)
-- GMT-8 hr std. time, RJ Rcvr 39° 8' 0" N, 121° 1' 0" W

Two laws Newton and Einstein didn't discover:
1. Time is money.
2. Matter will be damaged in direct proportion to its value.

Web Page: <home.earthlink.net/~mtnviews>
sierra_mtnview -at- earthlink -dot- net
Imaginarium Museum: <home.earthlink.net/~mtnviews/imaginarium.html>
 
M

Mike C. Fletcher

W. Watson said:
I have a 640x480 b/w bmp image file that can be converted to a dat
file. I would like to convert the value of each pixel that is below
say 120 units to exactly 40 units.
....

python -c "open('mask.dat','w').write(chr(40)*640*480)"

Well, if you're going to take this as the baseline, then we can do some
pretty darn simple stuff indeed:
.... """Create 256-char mapping of destination characters"""
.... return string.maketrans( "".join( [chr(x) for x in
range(threshold)]), chr(target) * threshold )
...."'''Test of the glVertex function\r\n\r\nDrawing TT glyphs as Cubic
splines...\r\n\thttp://support.microsoft.com/support/kb/articles/q243/2/85.asp\r\n\r\n'''\r\nfrom
OpenGLContext import testingcontext\r\nBaseContext"120

Of course, most Python programmers, when faced with a problem like this
would turn to either PIL (Python Imaging Library) or Numpy (Numeric
Python), but if all you need is quick-and-dirty, there you go.

Have fun,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
 
W

W. Watson

Mike said:
W. Watson said:
I have a 640x480 b/w bmp image file that can be converted to a dat
file. I would like to convert the value of each pixel that is below
say 120 units to exactly 40 units.

...

python -c "open('mask.dat','w').write(chr(40)*640*480)"


Well, if you're going to take this as the baseline, then we can do some
pretty darn simple stuff indeed:
... """Create 256-char mapping of destination characters"""
... return string.maketrans( "".join( [chr(x) for x in
range(threshold)]), chr(target) * threshold )
..."'''Test of the glVertex function\r\n\r\nDrawing TT glyphs as Cubic
splines...\r\n\thttp://support.microsoft.com/support/kb/articles/q243/2/85.asp\r\n\r\n'''\r\nfrom
OpenGLContext import testingcontext\r\nBaseContext"'((((((((((((((((((((((x((((((((((((((((((((((((((y(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((x(((((((((((((((((((((x((((((((((((x('
120

Of course, most Python programmers, when faced with a problem like this
would turn to either PIL (Python Imaging Library) or Numpy (Numeric
Python), but if all you need is quick-and-dirty, there you go.

Have fun,
Mike
Having only seen the example snipet I gave as an example of python coding, what you
wrote comes as a real surprise. This reminds me of a programming language called APL.
It really had odd syntax. What are >>>, ..., and all those {{{{{? Not to mention the
120 at the end. The snipet suggests that a python program can be run as a command
line (python -c) like Perl. I would have thought a multi-line program to be executed
would look something like
python -c {line 1, line 2, line 3, etc.} It looks like I need to look at some
python examples to get a feel for what this is about.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top