MathGroup Archive 2009

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

Search the Archive

Re: Image[], Graphics[Raster[]]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100407] Re: Image[], Graphics[Raster[]]
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 2 Jun 2009 06:49:52 -0400 (EDT)
  • References: <6147782.1243412890107.JavaMail.root@n11> <200905280829.EAA14200@smc.vnet.net> <h00ctf$pdv$1@smc.vnet.net>

Hi,

what do you want ? a solution to the problem or
a pointer to the documentation ?

And it is easy to write a similar function by your self
because Graphics[Raster[]] is still working,
one of the design errors in Image[] is that it has no
dimension/size/position. But for the new  line integral
convolution one needs to place a bitmap in a coordinate
system. So Mathematica *must* support Raster[] because
otherwise, the line integral convolution would not work.

In fact my own image processing package has a function
ImageToGraphicsObject[] that make a raster from the Image[]
and add a ImageRectangle option to Image[] because otherwise
I would not be able to use Mathematica for my
research work for image registration.

So here is the one, that is documented by its source

DigitalImageQ[_Image]:=True
DigitalImageQ[Graphics[Raster[__],___]]:=True
DigitalImageQ[img_]:=Image`PossibleImageQ[img]


If[(ImageRectangle /. Options[Image]) === ImageRectangle,
  Unprotect[Image];
  Options[Image] = Append[Options[Image], ImageRectangle -> Automatic];
  Protect[Image];
  ]

ImageRectangle[img_?DigitalImageQ]:=
   Module[{pos},
   	pos=ImageRectangle /. Options[img] /. (ImageRectangle->Automatic);
   	If[Automatic===pos || !MatchQ[pos,{{_,_},{_,_}}],
   	  Return[{{0,0},ImageDimensions[img]}];
   	 ];
     pos	
   ]	 	

ImageColorFunction[img_?DigitalImageQ]:=
Block[{cs,cf},
   cs=ColorSpace /. AbsoluteOptions[img];
   Which[
   	cs==="Grayscale", cf=GrayLevel,
   	cs==="RGB",       cf=RGBColor,
   	cs==="CMYK",      cf=CMYKColor,
   	cs==="HSB",       cf=Hue,
   	True,cf=GrayLevel
   ];
   cf
]				

Options[ImageToGraphicsObject]={ColorFunction->Automatic,ImageRectangle->Automatic,ColorFunctionScaling->True}

ImageToGraphicsObject[img_?DigitalImageQ,opts:OptionsPattern[ImageToGraphicsObject]]:=
   Module[{typ,rect,raster,range,cfun,cfs},
   	typ=ImageType[img];
   	rect=OptionValue[ImageRectangle];
   	If[Automatic==rect,
   	  rect=ImageRectangle[img]
   	 ];
   	range={Min[#],Max[#]} & [Flatten[ImageData[img,typ]]];
   	cfun=OptionValue[ColorFunction];
   	If[Automatic===cfun,
   	  cfun=ImageColorFunction[img]
   	 ];
   	cfs=OptionValue[ColorFunctionScaling];
 
Raster[Reverse[ImageData[img,typ]],rect,range,ColorFunction->cfun,ColorFunctionScaling->cfs]
   ]


Hopefully I have not forgotten anything ... mail me if yes,
You can have the package for Windows/MacOS X

Regards
   Jens



lehin.p at gmail.com wrote:
> On May 31, 2:32 pm, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
> wrote:
>> Oh mixing is easy:
>>
>> img = Import["http://www.stephenwolfram.com/img/home/sw-portrait.jpg";]
>> Graphics[
>>   {Image`ToGraphicsRaster[img][[1]],
>>    Circle[{110.5, 110.5}, 10]}]
>>
>> draw a circle on the image.
> 
> Hello,
> Big thanks. But it looks like undocumented function. Where the
> function "Image`ToGraphicsRaster" is documented? I have not found
> anything in the Documentation about this.
> 


  • Prev by Date: Re: matching misspelled names
  • Next by Date: Re: RandomReal gets stuck
  • Previous by thread: Re: Image[], Graphics[Raster[]]
  • Next by thread: Re: Image[], Graphics[Raster[]]