MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reading txt files with Digital Image Processing Package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85143] Re: Reading txt files with Digital Image Processing Package
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 30 Jan 2008 06:05:16 -0500 (EST)
  • References: <fneg76$dd0$1@smc.vnet.net>

Hi,

*my* image processing package has a function

(* Convert a matrix to an image *)
ImageMatrixQ[bm_?MatrixQ] := True
ImageMatrixQ[bm_?(MatrixQ[#, VectorQ] &)] := True
ImageMatrixQ[_] := False

MatrixToImage[data_?ImageMatrixQ] :=
  Module[{dim, ny, nx, ch, mind, maxd, colorf},
   dim = Dimensions[data];
   {ny, nx} = Take[dim, 2];
   If[3==Length[dim],
    ch = Last[dim],
    ch = 1
    ];
   colorf = Switch[ch,
     1, GrayLevel,
     2, GrayLevel,
     3, RGBColor,
     4, RGBColor
     ];
   {mind, maxd} = {Min[#], Max[#]} &[Flatten[data]];
   Graphics[
    Raster[
     Developer`ToPackedArray[data], {{0, 0}, {nx, ny}}, {mind, maxd},
     ColorFunction -> colorf
     ], AspectRatio -> Automatic,
    PlotRange -> {{0, nx}, {0, ny}}, ImageSize -> {nx, ny}
    ]
   ]

you can at least use this function, Export[] the result and
import it again and DIP will work with it.

But take care, because the Export/Import trick will rescale
the output to 8 or 16 bit and your original data range
is lost ..

Regards
   Jens


GidiL wrote:
> Dear All!
> 
> I would greatly appreciate any help you could give me with the
> following.
> 
> I have an image from an experiment I carried out. The image itself is
> not in a format with which Mathematica can work. So I have two options
> to save it either as an (x,y,z) ASCII file or a matrix ASCII file.
> 
> I am not sure which is the best one to use to read into Mathematica,
> so I tried both. Needless to say, these are both Lists.
> 
> Since these are not by default images (such as bitmap, jpeg or tiff),
> Digital Image Processing does not recognise them as images. Hence I
> cannot import them using the ImageRead command, nor are they
> recognized as Image Data. I resorted to simple Import and
> ListDensityPlot commands in order to import the data into Mathematica
> and visualize it.
> 
> Now I want to work with these images. I want to be able to use
> LineProfile and LineSelectGUI to choose the lines I want. Is this
> possible? Simply put, how can I make DIP recognize these files as
> Image Data?
> 
> Thanks,
> Gideon
> 


  • Prev by Date: Re: Polylog equations
  • Next by Date: Re: Converting Radians into Degrees into Mathematica 6.01
  • Previous by thread: Re: Reading txt files with Digital Image Processing Package
  • Next by thread: Voronoi diagram colours