MathGroup Archive 2009

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

Search the Archive

Re: Problems combining new v7.0 Image command with other graphics


just the function for 2)

MaskImageOperation::invmdim =
   "Image and mask must have the same dimensions.";
MaskImageOperation::invrdim =
   "Image and transformed image must have the same dimensions. Will \
padd the transformed image.";

MaskImageOperation[op_,       (* the function applied to the image *)
   img_?Image`PossibleImageQ,  (* the image and the mask *)
   mask_?Image`PossibleImageQ] /;
   ImageType[mask] === "Bit" :=
  Module[{oimg, typ, idim, padlst},
   typ = ImageType[img];
   oimg = op[img];
   idim = ImageDimensions[img];
   If[idim =!= ImageDimensions[mask],
   If[idim =!= ImageDimensions[oimg],
    padlst = ImageDimensions[oimg] - idim;
    padlst =
     If[EvenQ[#], {#, #}/2, Floor[{#, #}/2] + {0, 1}] & /@ padlst;
    oimg = ImagePad[oimg, padlst]
    Map[If[#[[1]] == 1, #[[2]], #[[3]]] &,
     Transpose[{ImageData[mask, "Bit"], ImageData[oimg, typ],
       ImageData[img, typ]}, {3, 1, 2}],


img = Import["lena.png"];
bimg = Binarize[ColorConvert[img, "Graylevel"]]

  GaussianFilter[#, {6, 6}] &, img, bimg]

will work. However apply the function not to the whole image
will not work, because many operations (like the Gauss filter here)
would get problems with the irregular boundaries. The
interactive image processing programs like PhotoPaint or PhotoShop
also process the full image (in the most cases) and
combine it with the original using the mask.


Mac wrote:
> The new image processing features of Mathematica are very useful and
> very much needed at least for my work. There are, however, three key
> features that are missing in my opinion or are implemented in an
> inconsistent fashion:
> 1) The ability to manipulate image data that is not scaled between 0
> and 1. In many cases image data represent useful physical information
> (e.g. brightness of stars, temperature etc...) which are usually
> encoded in reals. Scaling everything between 0 and 1 to be able apply
> the image processing routines like ImageCrop[], ImageTake[] and
> ImagePartition[] seems clumsy and unnecessary. My previous experience
> with the IDL language didn't require jumping through these kind of
> hoops. Note that the Raster[] command does give the possibility of
> scaling data on the fly for display.
> 2) The ability to apply image processing to user defined regions. It
> would be very useful to be able to define regions of interest (say
> with polygons) and apply image processing or information extraction
> techniques to this region only instead of treating the whole image.
> 3) Inconsistent behaviour with respect to combined graphics. An
> example is given below illustrating how difficult it is to combine
> Image data with other Mathematica graphics. The fact that the Show[]
> command works with a single image but not with multiple image +
> graphic combinations seems to be inconsistent with the syntax and
> purpose of the Show[] command. Using Raster[] we get the expected
> behaviour but cannot use the new image processing routines of v. 7.0.
> If you have any work arounds for the above problems or comments I
> would be interested in hearing these.
> Mac
> Example:
> Generate an small test image
> img = RandomReal[{0, 1}, {100, 200}];
> This works and produces a graphic in the notebook
> Image[img]
> This also works
> Show[Image[img]]
> However, although show works with a single image, showing several
> graphics combined produces the error "Image is not a Graphics
> primitive" even though the Show[] syntax is respected.
> Show[Image[img, ImageSize -> 200], Graphics@Circle[]]
> This also produces a the same error
> Graphics@Image[img]
> whereas graphics can be combined using the old-fashioned Raster
> command without problem
> Show[Graphics@Raster[img], Graphics[{Red, Circle[{100, 50}, 40]}]]

  • Prev by Date: Re: Animation = Translation + Vibration, But How?
  • Next by Date: Transformation matrix
  • Previous by thread: Re: Problems combining new v7.0 Image command with other graphics
  • Next by thread: Re: Problems combining new v7.0 Image command with other graphics