s3d image processing with netpbm-tools

Post Reply
User avatar
iondrive
Sharp Eyed Eagle!
Posts: 367
Joined: Tue Feb 10, 2009 8:13 pm

s3d image processing with netpbm-tools

Post by iondrive »

howdy all,

I wonder if I'm the only one who knows/cares about this set of command line programs but anyway, I'd like to tell you about it if you care. It's Netpbm-tools and its home is on sourceforge: http://netpbm.sourceforge.net/" onclick="window.open(this.href);return false; and you can get the Windows version from here:

http://gnuwin32.sourceforge.net/packages/netpbm.htm" onclick="window.open(this.href);return false;

It's not specifically for s3d but I've found it to be a handy set of commands that are scriptable so that you can process many files in a batch and lately I've been using them for various things so I thought I'd share my info with anyone who cares or needs it. I will be mostly giving examples for Windows users but Linux users should have an easy time adapting the concepts to Linux bash scripts.


Examples:

A .jps to anaglyph converter:
One thing I've done lately is to write a script that converts .jps files to anaglyph and you can use it to convert a whole directory at a time. I'm sure other programs can do that too but if anyone needs it, they can use this one and tweak the colors or techniques using any ideas of their own that they might have. It's pretty easy to hand-tune your routines and that may be a capability that other converters lack.

an interlaced/checkerboard mask generator:
If you're dealing with interlaced or checkerboard 3d, you might need a mask that consists of only black and white pixels in a pattern of alternating stripes or else in a checkerboard pattern. You can get such a mask easily by using some of these commands in the right way and then you can use them to compose or decompose interlaced s3d images.

a blue-line-code adder:
Another thing I've done is to make a script that adds BLC code to my 3d screenshots and then I can use them with sView (stereoscopic viewer) and when I'm using it in fullscreen in shutterglass mode, my glasses automatically start shuttering and they're always in sync with whatever screenshot I'm looking at. The only drawback is that if I zoom in or out, then I lose the blue-line detection. Still, it's pretty nice to have it work as it does.

other apps?
If you're very clever, you may be able to use these tools to come up with some different ideas about how to convert anaglyph to non-anaglyph 3d but I think that's pretty hard to do a good job with but you can get "good enough" results I think, possibly depending on the video.


Anyway, if you're interested in these tools, you can choose to install the "complete package" from the above link and then add ";C:\Program Files\GnuWin32\bin" to your PATH if you installed to the default location. Then in your Start menu, "NetPbm" will probably be under "GnuWin32".


Here's the user manual:
http://netpbm.sourceforge.net/doc/" onclick="window.open(this.href);return false;

and here's a good index of commands available:
http://netpbm.sourceforge.net/doc/directory.html" onclick="window.open(this.href);return false;


And here's some basic info on the filetypes:

.pbm - portable bitmap: 1 bit per pixel, black and white pixels only
.pgm - portable graymap: generally 8 bits per pixel meaning you have 256 shades of gray.
.ppm - portable pixmap: generally 24 bits per pixel full RGB color.
.pnm - portable anymap: any of the above
.pam - portable anymap or arbitrarymap: any of the above but can have an alpha channel.

These filetypes are lossless but there can be some color conversion involved so I suppose there is some imperceptible data loss. Judge for yourself. Filesizes are larger than jpeg since it's lossless. There's binary and ascii versions of each pbm, pgm and ppm but you'll almost always be using binary. Sometimes you'll wonder if you really need to convert between formats in order to use a command so just try your idea with your current format and see if it works. For example, the pamcomp command says it uses a graymap as an alpha mask but you can go ahead and use a pixmap and it works fine. You don't need to convert your ppm to pgm in order to use it as an alpha mask in that case.

and here's the Wikipedia page:
http://en.wikipedia.org/wiki/Portable_anymap" onclick="window.open(this.href);return false;

Onward...
Last edited by iondrive on Mon May 02, 2011 5:11 am, edited 1 time in total.
User avatar
iondrive
Sharp Eyed Eagle!
Posts: 367
Joined: Tue Feb 10, 2009 8:13 pm

s3d checkerboard ops

Post by iondrive »

Here are the lines that generate various 1280x720 masks - one line per output file format:

*** create a 1280x720 white-black checkerboard pbm, pgm, ppm, or png
pbmmake -gray 1280 720 > WB-checkerboard-1280x720.pbm
pbmmake -gray 1280 720 |pgmtopgm > WB-checkerboard-1280x720.pgm
pbmmake -gray 1280 720 |ppmtoppm > WB-checkerboard-1280x720.ppm
pbmmake -gray 1280 720 |pnmtopng > WB-checkerboard-1280x720.png

Warning: If another program doesn't work with your png file, you may need to add "-force" in order to get a png file with more compatible characteristics. If that doesn't work, then add a "ppmtoppm" in your filter chain in order to go from 1 bpp to 24 bpp and that should fix it. For example, mplayer needs this in order to play this png file:

pbmmake -gray 1280 720 |ppmtoppm |pnmtopng -force > WB-checkerboard-1280x720.png


Q: pbmmake -gray makes a checkerboard pattern?

A: Yes, since the pbmmake command makes a pbm, the pixels are all either black or white which means that the "-gray" is actually a pixel-by-pixel checkerboard pattern which is just what we need to process checkerboard 3d. Nice coincidence, eh? I use "WB" in the output filename to tell me that the checkerboard is "white-black" which means the top left corner pixel is white. For the inverse I use "BW" instead and here's how to get it. You just use the pnminvert command although you might not actually need the inverse.

*** invert an image with pnminvert
pnminvert WB-checkerboard-1280x720.pbm > BW-checkerboard-1280x720.pbm

Alternatively you could create the "BW" version without making the "WB" version:

*** create a 1280x720 black-white checkerboard pbm
pbmmake -gray 1280 720 |pnminvert > BW-checkerboard-1280x720.pbm

but for now, well stick with pbm for the next stuff.


Composing a checkerboard 3d image:

If you have left and right jpegs, use jpegtopnm and then use pamscale (if needed) to get your images to be all the same correct resolution for your system (either 1280x720 or 1920x1080) and name them L.ppm, R.ppm, and WB-CB.ppm for your checkerboard mask. The images should be formatted for widescreen viewing (16x9) so if you need to crop them use pamcut, and if you need to pad them use pnmpad. Then use the following command to make your composite image.

*** Composing a checkerboard 3d image:
pamcomp -alpha=WB-CB.pbm L.ppm R.ppm >3d-composite.ppm

The left view is the overlaying image and the right view is the underlying image and the checkerboard is the alpha-mask where white is opaque so that the top-left corner of the output is from the left-view. Think of the mask as white paper with black holes in it. The paper gets put on the underlying image and the overlying image only shows up on the white parts of the paper. Although the -alpha image file is supposed to be a grayscale pgm, I find that ppm's and pbm's also work.


Decomposing a checkerboard 3d image:

OK, so you have a checkerboard image and want to extract the originals, well you can't really since half the pixels are gone but you can get a good approximation. Just use pamcomp some more after we make a black.pbm with "pbmmake -black 1280 720 >black.pbm" and use that as the underlying image.

*** Extracting a left-eye-view from a checkerboard 3d image:
pamcomp -alpha=WB-CB.pbm 3d-composite.ppm black.pbm >L-odd.ppm

Let's call the top left-most pixel odd and this command makes the final output have a black checkerboard pattern on it but that's just a consequence of the system. For the right-eye-view use the -invert option:

*** Extracting a right-eye-view from a checkerboard 3d image:
pamcomp -alpha=WB-CB.pbm -invert 3d-composite.ppm black.pbm >R-even.ppm

Inverting the mask makes sense but, if we wanted to, we could have gotten the same result by not inverted the mask and just changing the order of the files like this:
pamcomp -alpha=WB-CB.pbm black.pbm 3d-composite.ppm >R-even.ppm
so that the top-left corner would be black like it's supposed to be in this case.


Interpolating missing pixels with pnmconvol:

OK, now how do we interpolate the in-between pixels that are now black? pnmconvol to the rescue... pnmconvol lets you define your own convolution matrix and employ it on your image. Isn't that awesome?! Remember when I mentioned that pnm files could be ascii? Here's the one time I've used that to define a pgm image file. Copy/paste the following into a text file and rename it matrix.pgm and you've made a pgm image file by hand that you can look at with the GIMP.

Code: Select all

P2
3 3
4
0 1 0
1 0 1
0 1 0
Basically when you use this as a 3x3 convolution matrix, all it does is average the four adjacent neighboring pixels in order to get the new color of the center pixel. This will generate a new image that also has checkerboard black pixels but it will be complementary to the original half-res-view.ppm. Add these two pixmaps together and we will have our reconstructed image.

*** Using pnmconvol to build half-res left/right images:
pnmconvol -nooffset matrix.pgm L-odd.ppm > L-even.ppm
pnmconvol -nooffset matrix.pgm R-even.ppm > R-odd.ppm

Then add the two halves together to get the final reconstruction:
pamcomp -alpha=WB-CB.pbm L-odd.ppm L-even.ppm > reconstructed-Left.ppm
pamcomp -alpha=WB-CB.pbm R-odd.ppm R-even.ppm > reconstructed-Right.ppm


Horizontal vs Vertical vs Diagonal interlacing: which is best?
Now that we know how to do all this, we can start with a .jps screenshot, compose it and decompose it to "recover" the originals and we can compare the reconstructed images using these 3 different kinds of interlacing and decide which one we think is the best. I think horizontal is the best because checkerboard reconstructions result in a kind of rail-road track pattern on vertical and horizontal lines due to the interpolating and it seems a little better than vertical. It may depend on the image but the HUD in your games often has straight lines that don't look good with checkerboard. Comparing vertical and horizontal, it seems that small text is a little easier to read with horizontal than vertical. OK, whatever.


--- iondrive ---

PS: there are, of course, different ways to do this and they might be faster too. Mostly I'm referring to pamarith, with which you could -add L-even.ppm and L-odd.ppm to get reconstructed-Left.ppm or else you could multiply the mask with the 3d-composite.ppm to zero-out (blacken) a checkerboard pattern and extract left/right images that way if you want. I just chose to use pamcomp because it needs a good example like this to understand it better.
Last edited by iondrive on Tue May 03, 2011 6:07 am, edited 1 time in total.
User avatar
iondrive
Sharp Eyed Eagle!
Posts: 367
Joined: Tue Feb 10, 2009 8:13 pm

color-code generation

Post by iondrive »

Hi all,

I just posted some color-code data in the dongle-Activator thread and now I want to show those interested how to use that data to make their own activator. Here's a link to the other thread:

http://www.mtbs3d.com/phpBB/viewtopic.p ... 505#p59505" onclick="window.open(this.href);return false;

and here's the key data we're going to use for your E-Dim/H3D/X3D/3D-World dongle. Note this may not apply to older H3D dongles. Each letter represents one horizontal line across the entire top of the screen, 1-pixel tall.
(b=black, r=red, y=yellow, g=green, x=any color (background color, whatever is on the screen))


top of screen color line codes: from ED-Activator (R3D Controller 2.7.0.0)

rrggyyyybb(xxx...) - turns off any mode
rrggyyyyrr(xxx...) - turns on interlaced mode (top line goes to left eye)
rrggyyyybr(xxx...) - turns on interlaced mode in reversed mode (top line goes to right eye, Zalman style)
rrggyyyyyy(xxx...) - turns on sync-doubling mode
rrggyyyygg(xxx...) - turns on page-flipping mode

What we have to do is make a little video at your current screen resolution and play it in fullscreen mode with mplayer using either openGL mode or non-accelerated directx or x11 in the case of Linux users. But as it turns out, mplayer can just play png files as if they are frames from a video so that's what we'll do. So then all we have to do now is make some small png files with the color-codes that we care about and then mplayer can stretch that to match your fullscreen res. Ready? GO!

The dimensions and image file format:
Let's make 16x16 pixel square png files since jpegs are lossy and it's often better to make video files that have dimensions that are multiples of 16. Also, I can post the png files to this page and you can just download them. :)

The modes:
For now, let's just stick to turning the glasses on and off and forget about the other modes like sync-doubling and interlaced modes. Save them for later if you need them.

rrggyyyybb(xxx...) - turns off any mode
rrggyyyygg(xxx...) - turns on page-flipping mode, just shutters the glasses, does not start line-blanking or sync-doubling.

Filenames:
Normally you would use filenames with .ppm extensions but in this case, let's just not use any extensions at all for the ppm's. You'll see why it makes things simpler in a minute. Let's make some lines!!! (16 pixels wide by 1 pixel tall)

ppmmake rgb:00/00/00 16 1 > b
ppmmake rgb:ff/00/00 16 1 > r
ppmmake rgb:ff/ff/00 16 1 > y
ppmmake rgb:00/ff/00 16 1 > g
ppmmake rgb:00/00/00 16 6 > padding

This follows the line-codes given above. b is for black, not blue. There is no blue in this case and the padding is 6 black lines in one 16x6 block which is what we need to add to the bottom of our image in order to reach 16x16 square. Now all we need to do is stack them top-down in the right order using "pnmcat -tb":

pnmcat -tb r r g g y y y y b b padding |pnmtopng -force > glasses-off.png
pnmcat -tb r r g g y y y y g g padding |pnmtopng -force > glasses-on.png


OK, now what?
Well, we have our png image files. Now all we have to do is play them with mplayer. You must know your screen res for this next part and you must have mplayer installed of course. If your display is currently 1024 pixels wide:

*** turn on glasses for 1024x768 res.
mplayer mf://glasses-on.png" onclick="window.open(this.href);return false; -noborder -geometry 0:0 -vo gl -loop 25 -vf scale=1024:16,dsize

and to turn them off

*** turn off glasses for 1024x768 res.
mplayer mf://glasses-off.png" onclick="window.open(this.href);return false; -noborder -geometry 0:0 -vo gl -loop 25 -vf scale=1024:16,dsize

Of course, tweak as needed. For too much understanding, see the mplayer thread:
http://www.mtbs3d.com/phpBB/viewtopic.php?f=27&t=4521" onclick="window.open(this.href);return false;
Jump to page three for this topic specifically ("using mplayer as an activator").

One alternate method is to make a video file out of the png's and play that, but another approach is to expand the video to fullscreen like this:

mplayer mf://glasses-off.png" onclick="window.open(this.href);return false; -vo gl -loop 25 -vf scale=1024:16,expand=1024:768:0:0,dsize -fs

Interlaced CRT modes:
Finally, if your monitor is in an interlaced display mode (not line-blanking), then ED-Activator won't work because it doesn't expect you to have your monitor in that mode and isn't made for that. But you can still use mplayer to control them by using the above commands after changing the 16 to 32 to make the lines span twice the normal vertical height. That will compensate for the interlaced mode as long as you use -sws 4 in your mplayer command line. Once again, more info in the mplayer thread.

And here's the png's so you don't have to make them yourself:
Turn on glasses:
glasses-on.png
Turn off glasses / stop line-blanking / stop sync-doubling:
glasses-off.png
Turn on glasses plus start sync-doubling mode:
sync-doubling-LR.png
Turn on glasses plus start line-blanking
line-blanking-LR.png
As above but top-line goes to right eye instead of left
line-blanking-RL.png
There seems to be no pattern that can start sync-doubling for Right-over-Left images (no sync-doubling-RL, only sync-doubling-LR). You must use Left-over-Right images for sync-doubling mode UNLESS you are using a DLP projector that has a frame-delay and you have no parallax inverter. Then use Right-over-Left views but don't worry, mplayer can swap them on the fly.

OK, if I forgot anything, then I'll edit later.

Later,

--- iondrive ---

PS: oh yeah, you can put these commands into .bat files and put shortcuts on your desktop and then just double-click to use them. Nice eh? Don't drag them to your desktop because they reference the png files. Make sure you're using shortcuts instead or else change the command to use the full pathnames for the png files. That should work too. Bye now.
You do not have the required permissions to view the files attached to this post.
Last edited by iondrive on Fri May 13, 2011 4:13 am, edited 2 times in total.
User avatar
cybereality
3D Angel Eyes (Moderator)
Posts: 11407
Joined: Sat Apr 12, 2008 8:18 pm

Re: s3d image processing with netpbm-tools

Post by cybereality »

Very nice work. I'm sure someone will find it useful.
User avatar
iondrive
Sharp Eyed Eagle!
Posts: 367
Joined: Tue Feb 10, 2009 8:13 pm

Vertically striped bitmap generation script

Post by iondrive »

Hi Cyber,

Thanks for the pat on the back, you deserve one as well for all your efforts and giving away free anaglyph glasses and stuff like your homemade parallax barrier project. It's grrrrrreat as well as magically delicious. (breakfast cereal references) Too bad the LCD monitors often have vertical stripes of RGB colors for sub-pixels. Parallax barrier would work better with horizontal rows of sub-pixel colors instead. I wonder if the 3DS uses horizontal rows. I'll bet it does. It would be a design mistake if it didn't. Can you check this with a magnifying glass? Anyway, here's something that you can use to test your parallax barrier... vertical stripes! Make a png with the fullscreen res of your display and if your parallax barrier is perfect, then one eye would see only black and the other would only see white when viewed in fullscreen mode. You can use mplayer for this:

*** fullscreen 1:1 pixel-mapped vertical stripes for a 1280x720 display
mplayer mf://WB-V-stripes-1280x720.png" onclick="window.open(this.href);return false; -loop 0 -fs -vo directx:noaccel

Q or escape to quit, note that this can be used on CRT monitors to check beam alignment via moire pattern observation. Anyway...

Hi all,

Sometimes you need to make a bitmap of vertical stripes in order to use as a mask for some 3d image processing so here's a little script that can make vertical black and white stripes. It uses pnmcat and a loop to build up a bigger pixmap and then crops the dimensions you want. Then there's a Horizontal version as well.

Code: Select all

@echo off


rem Filename: make-V-stripes.bat


rem     Usage: 

rem Enter "make-V-stripes.bat width height" or just double-click the file and
rem use interactive mode to enter width and height of desired output image.
rem This file contains many lines that you can comment-out or uncomment in
rem order to tweak it to your desired functionality. If you need the inverse
rem bitmap, then use "pnminvert WB-filename.pbm > BW-filename.pbm" but note
rem that some programs like pamcomp have an invert-mask option so that you 
rem don't really need the inverse bitmap. Output is set to be a filename
rem with the pattern: WB-V-stripes-"WidthxHeight".pbm where "WB" stands for
rem "white-black alternating" and means that the left-most top pixel is white.
rem Another output is a .png file since it's a more common format.


rem     Purpose:

rem to make a pixel-by-pixel vertically striped black and white bitmap
rem in various lossless output formats for the purpose of using it as a mask
rem for constructing or deconstructing vertically interlaced stereo 3d images
rem or anything else you can think of. The basic idea here can be expanded to
rem more than two camera angles for the purpose of creating multiple-
rem perspective images for use with lenticular lensing or parallax-barrier 3d
rem viewing systems which can sometimes use up to 10 or more camera angles.


rem     Requirements:

rem This script uses the netpbm-tools for Windows from
rem http://gnuwin32.sourceforge.net/packages/netpbm.htm
rem Choose the complete package and install if you haven't already.

rem !!! WARNING !!!
rem the netpbm-tools bin directory must be on your PATH.
rem It should be something like "C:\Program Files\GnuWin32\bin" 
rem unless you installed it to a different folder.


rem Author: iondrive from the MTBS3D.com forums
rem Copyright: Public Domain, use at own risk
rem Date: 5-3-2011



rem     initialize some variables including Width and Height

set ion_W=%1
set ion_H=%2


rem     Basic error-checking. Requested res must be at least 1 1
rem     go print error message and exit if input is blank or less than 1.

if "%1"=="" set /P ion_W="Enter desired output width: "
if "%2"=="" set /P ion_H="Enter desired output height: "
if %ion_W% LSS 1 GOTO error
if %ion_H% LSS 1 GOTO error


rem     initialize some bitmaps

pbmmake -white 1 %ion_H% | ppmtoppm > white-line.pbm
pbmmake -black 1 %ion_H% | ppmtoppm > black-line.pbm
pnmcat -lr white-line.pbm black-line.pbm > WB.pbm
pnmcat -lr WB.pbm WB.pbm WB.pbm WB.pbm > WBx4.pbm
pnmcat -lr WBx4.pbm WBx4.pbm > final-temp.pbm
copy /b final-temp.pbm final.pbm



rem     start looping to build bitmap by adding 16 lines per loop
rem     because it's much faster than adding only 2 lines per loop.

set /a loops = %ion_W% / 16
for /L %%I in (1,1,%loops%) do (

pnmcat -lr final.pbm WBx4.pbm > final-temp.pbm
pnmcat -lr final-temp.pbm WBx4.pbm > final.pbm

)


rem     do final crop and then write output file.
rem     output filename - "white/black Vertical stripes - res"

pamcut 0 0 %ion_W% %ion_H% final.pbm > WB-V-stripes-%ion_W%x%ion_H%.pbm

rem     if you need pgm or ppm instead of pbm:
rem pamcut 0 0 %ion_W% %ion_H% final.pbm |pgmtopgm > WB-V-stripes-%ion_W%x%ion_H%.pgm
rem pamcut 0 0 %ion_W% %ion_H% final.pbm |ppmtoppm > WB-V-stripes-%ion_W%x%ion_H%.ppm

rem     if you need png instead of pbm/pgm/ppm
pamcut 0 0 %ion_W% %ion_H% final.pbm |pnmtopng -force > WB-V-stripes-%ion_W%x%ion_H%.png



rem     cleanup

del white-line.pbm black-line.pbm 
del WB.pbm WBx4.pbm
del final-temp.pbm final.pbm
set ion_W=
set ion_H=
set loops=


rem     skip error message
GOTO end

:error
echo Program Terminated. Desired resolution must be at least 1 1

:end


rem eof
I'll put the Horizontal version in a separate post. If you want to check the image files for accuracy, make a small one and view it with Paint zoomed in or else use mplayer's scale or zoom functions.

*** zooming in on a cropped top-left corner portion of an image with mplayer
mplayer -sws 4 -vf crop=32:32:0:0,scale=256:256,dsize mf://WB-V-stripes-1280x720.png" onclick="window.open(this.href);return false; -loop 0 -vo directx:noaccel

next... make-H-stripes.bat
User avatar
iondrive
Sharp Eyed Eagle!
Posts: 367
Joined: Tue Feb 10, 2009 8:13 pm

Horizontally striped bitmap generation script

Post by iondrive »

OK, here's the Horizontal version in case someone needs a mask of 1-pixel-wide black and white horizontal stripes. Just input your desired dimensions.

Code: Select all

@echo off

rem Filename: make-H-stripes.bat


rem     Usage: 

rem Enter "make-H-stripes.bat width height" or just double-click the file and
rem use interactive mode to enter width and height of desired output image.
rem This file contains many lines that you can comment-out or uncomment in
rem order to tweak it to your desired functionality. If you need the inverse
rem bitmap, then use "pnminvert WB-filename.pbm > BW-filename.pbm" but note
rem that some programs like pamcomp have an invert-mask option so that you 
rem don't really need the inverse bitmap. Output is set to be a filename
rem with the pattern: WB-H-stripes-"WidthxHeight".pbm where "WB" stands for
rem "white-black alternating" and means that the left-most top pixel is white.
rem It also Outputs a .png file if that's what you need or can use.


rem     Purpose:

rem to make a pixel-by-pixel Horizontally striped black and white bitmap
rem in various lossless output formats for the purpose of using it as a mask
rem for constructing or deconstructing Horizontally interlaced stereo 3d images
rem or anything else you can think of.


rem     Requirements:

rem This script uses the netpbm-tools for Windows from
rem http://gnuwin32.sourceforge.net/packages/netpbm.htm
rem Choose the complete package and install if you haven't already.

rem !!! WARNING !!!
rem the netpbm-tools bin directory must be on your PATH.
rem It should be something like "C:\Program Files\GnuWin32\bin" 
rem unless you installed it to a different folder.


rem Author: iondrive from the MTBS3D.com forums
rem Copyright: Public Domain, use at own risk
rem Date: 5-3-2011



rem     initialize some variables including Width and Height

set ion_W=%1
set ion_H=%2


rem     Basic error-checking. Requested res must be at least 1 1
rem     go print error message and exit if input is blank or less than 1.

if "%1"=="" set /P ion_W="Enter desired output width: "
if "%2"=="" set /P ion_H="Enter desired output height: "
if %ion_W% LSS 1 GOTO error
if %ion_H% LSS 1 GOTO error



rem     initialize some bitmaps

pbmmake -white %ion_W% 1 | ppmtoppm > white-line.pbm
pbmmake -black %ion_W% 1 | ppmtoppm > black-line.pbm
pnmcat -tb white-line.pbm black-line.pbm > WB.pbm
pnmcat -tb WB.pbm WB.pbm WB.pbm WB.pbm > WBx4.pbm
pnmcat -tb WBx4.pbm WBx4.pbm > final-temp.pbm
copy /b final-temp.pbm final.pbm



rem     start looping to build bitmap by adding 16 lines per loop
rem     because it's much faster than adding only 2 lines per loop.

set /a loops = %ion_W% / 16
for /L %%I in (1,1,%loops%) do (

pnmcat -tb final.pbm WBx4.pbm > final-temp.pbm
pnmcat -tb final-temp.pbm WBx4.pbm > final.pbm

)


rem     do final crop and then write output file.
rem     output filename description: "white/black Horizontal stripes - res"

pamcut 0 0 %ion_W% %ion_H% final.pbm > WB-H-stripes-%ion_W%x%ion_H%.pbm

rem     if you need pgm or ppm instead of pbm:
rem pamcut 0 0 %ion_W% %ion_H% final.pbm |pgmtopgm > WB-H-stripes-%ion_W%x%ion_H%.pgm
rem pamcut 0 0 %ion_W% %ion_H% final.pbm |ppmtoppm > WB-H-stripes-%ion_W%x%ion_H%.ppm

rem     if you need png instead of pbm/pgm/ppm
pamcut 0 0 %ion_W% %ion_H% final.pbm |pnmtopng -force > WB-H-stripes-%ion_W%x%ion_H%.png



rem     cleanup

del white-line.pbm black-line.pbm 
del WB.pbm WBx4.pbm
del final-temp.pbm final.pbm
set ion_W=
set ion_H=
set loops=



rem     skip error message
GOTO end

:error
echo Program Terminated. Desired resolution must be at least 1 1

:end


rem eof
OK, I hope someone finds this useful. See previous post for more info. Remember that jpegs are lossy and not good for this kind of thing.
Post Reply

Return to “General Hardware & Software Technical Support”