I have some ascii data file with k columns and n rows filled with
decimal values. I would like to plot this as an image. In Matlab you
would just load the ascii file and plot it with imagesc which also
automatically scales the input values so you would get maximum
contrast.
In Tcl I found "image create" but as far as I discovered you can only
read files in image format. How could I display an n x k ascii file?
Any hints are welcome :)
Cheers,
Toby
First off a question, up until the last sentence you talk about creating an
*image* that is a plot, then you ask how to *display* a plot -- which one
are you after (the second is *much* easier to do then the first)?
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
ok. What I want is to display an RGB image from an ASCII n x k file
(tab seperated with n rows and k columns) containing decimal values.
e.g.
0.59 0.49 0.44 0.83 0.82
0.56 0.67 0.49 0.79 0.95
0.86 0.12 0.42 0.71 1.19
0.34 0.40 0.49 1.01 1.11
0.66 0.67 0.33 0.97 0.78
0.50 0.46 0.34 1.01 0.43
0.13 0.15 0.63 1.13 0.68
3.20 1.84 0.67 1.18 0.87
3.99 2.31 1.00 1.05 0.59
3.83 2.83 1.28 0.81 0.48
should result in an color image. I found PlPlot at http://plplot.sourceforge.net/.
I didn't figure out yet if it can work with that but it's seems a bit
too powerful for my purposes.
Regards,
Toby
Can for the above dataset you post a link to what your expected output will be?
Ok sorry I guess I didn't make yet it clear enough.
The above posted format is my input format (ascii text file). This I
want to display as a RGB image. I could imagine the following
scenarios:
1) convert the ascii file to image file (e.g. gif, bmp,...) then
load the image in tcl via the "create image" command
2) reading input file and converting it to an image object (without
creating an image as file) and then loading the image in tcl (here I
don't know if there are any image objects in tcl and wheter the
"create image" procedure would help
3) another one I dont know yet :)
Creating an RGB image is a bit difficult since my data values need to
be rescaled from n x k in [-9999,9999] to I^3 in [0,255].
Regards,
Toby
Hi Toby,
I used to do this kind of thing (or something similar, anyway) as a
research tech at the University of Washington. Your posting created
an itch I had to scratch :)
It hasn't been thoroughly tested, but it seems to work... Once you
have created the image, you can manipulate it using standard Tk photo
image commands (in the case of your dataset, [$photo copy -zoom] comes
to mind).
Does that accomplish your goal, at least in part?
Aric
Yes. Thats exactly what I was looking for.
Thanks a lot!!
I just copied the cmap values from Matlab and now I have an imagesc :)
Toby
Implemented it in my application. I just realized that there are only
discrete zoom levels possible ($zoomval).
set img [valuesToImg $imagedata]
set img2 [image create photo]
$img2 copy $img -zoom $zoomval
Really a pitty. This is not supported by the Tcl "image" command or? I
guess I need to do convolution. Do you know any package doing that?
Regards,
Toby
Németh József Gábor has written an enhanced photo image copy command.
I haven't used it, so I can't guarantee that it will do what you want,
but it looks promising: http://wiki.tcl.tk/11924
I imagine TclMagick could expand the image in a smoother way. Again,
I haven't tried it so I can't speak from personal experience.
http://tclmagick.sourceforge.net/TclMagick.html
Finally, if you want to do nitty-gritty matrix operations on your
data, there is Nap by Harvey Davies. Come to think of it, Nap offers
some visualization routines, too. http://tcl-nap.sourceforge.net/
How big is your dataset? If it is reasonably small (less than a
hundred thousand pixels) then for visualisation it might be better
implemented by drawing squares on the canvas. The canvas may be a bit
slow to draw to compared to an actual image but once drawn zooming in
and out is easy and very fast.