MathGroup Archive 1998

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

Search the Archive

Re: Re: Images in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14377] Re: [mg14295] Re: Images in Mathematica
  • From: Andrew Watson <abwatson at mail.arc.nasa.gov>
  • Date: Thu, 15 Oct 1998 00:29:15 -0400
  • References: <6vhj42$jfb@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

At 10:21 PM -0700 10/12/98, Lawrence Walker wrote:
>John,
>
>I am interested in trying to do the same thing.  I tried importing a
>bitmap file.  I then converted the cell to inputform.  The result was a
>collection of graphic objects called RGBColor[].  This might help since
>the picture is now in a form that can be manipulated.
>
>Lawrence Walker
>
>JOHN C ERB wrote:
>
>> Oct 06, 1998
>>
>> Greetings;
>>
>> I would like to be able to import a scanned image (e.g., medical x-ray
>> film) into Mathematica,
>> and be able to ascertain the x and y coordinates of an object on that
>> image (given that I have
>> an x-y scale already on the image).
>>
>> Is there a package already available for doing this?  If not, does
>> anyone have any suggestions
>> as to how I might approach this problem?
>>
>> Thank you,
>>
>> John C. Erb
>> email: John_C_Erb at prodigy.net

If you can get your image imto PBM format (see GraphicConverter) then
you can use the following functions to read and write image files
(grayscale or color). Detecting objects in mages is a large and complex
subject. Start by reading a book or two.

ReadPBM[ file_ ] :=
 Module[{stream,type,tmp,columns,rows,rw},
 rw := Read[stream , Word
   ,WordSeparators->{"\012","\015"," "}];
 stream = OpenRead[file];
 type = rw;
 {columns,rows} = ToExpression /@ {rw,rw};
 rw;Read[stream , Character];
	tmp = If[type == "P6"
	 ,Transpose[Fold[Partition
	    , ReadList[stream,Byte],{3,columns} ], {2,3,1}]
	 ,Fold[Partition,ReadList[stream,Byte],{columns}]];
 Close[stream];
 tmp]


WritePBM[ image_, file_, color_:True ] :=
 Module[{stream,rows,columns},
 stream=OpenWrite[file];
 {rows,columns}=ToString /@
       Take[Dimensions[image],-2];
 WriteString[stream,
  If[color,"P6","P5"]<>
  "\n"<>columns<>" "<>rows<>"\n255\n"];
 WriteBinary[stream,
   Flatten[If[color,Transpose[image,{3,1,2}],image]],
     ByteConversion->Identity];
 Close[stream];]

Andrew B. Watson
MS 262-2
NASA Ames Research Center
Moffett Field, CA 94035-1000
(650) 604-5419	(650) 604-0255 fax
abwatson at mail.arc.nasa.gov	http://vision.arc.nasa.gov/


  • Prev by Date: RE: Removing Outer Braces
  • Next by Date: How to load user defined packages?
  • Previous by thread: Re: Images in Mathematica
  • Next by thread: Re: StyleForm