Login  Register

Re: Convert a textfile to an image, HELP!

Posted by dscho on Sep 18, 2006; 10:32am
URL: http://imagej.273.s1.nabble.com/Convert-a-textfile-to-an-image-HELP-tp3701578p3701579.html

Hi,

On Mon, 18 Sep 2006, Liisa Palomaa wrote:

> I need some help!  I wonder if anyone knows if it is possible to
> convert textfiles to images in ImageJ.

You probably want to write a macro which uses File.openAsString(path), and
the split() function.

> 1. Read a single textfile (size 10*250) and convert to image

This would be done by

-- snip --
fileName = "image.txt";
width = 10;
height = 250;
newImage(fileName, "8-bit", width, height, 1);
contents = File.openAsString(fileName);
lines = split(contents, "\n");
for (i = 0; i < height; i++) {
        columns = split(lines[i], " ");
        for (j = 0; j < 10; j++)
                setPixel(j, i, columns[j]);
}
-- snap --

> 2. Read another textfile (size 3*30) and convert to image

see above

> 3. Match image 1 and image 2. Resize to a special size (20*500).

I do not know exactly what you mean by "match". Care to explain?

> 4. Take the images from step 3 and combine as channels in a single
> image. (Maybe I need to do this and the last step in Photoshop)

That is easy in ImageJ, too.

> 5. Read in RGB data from RGB images (for the same board that the
> textfiles are from) and create a image and merge to a final image.

You can even do that in a macro!

I think that it would help you most if you just went through
http://rsb.info.nih.gov/ij/developer/macro/macros.html
and then through some example macros at http://rsb.info.nih.gov/ij/macros/
like InvertImage.txt.

Hth,
Dscho