MathGroup Archive 2003

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

Search the Archive

Raster process

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40589] Raster process
  • From: Steve Gray <stevebg at adelphia.net>
  • Date: Thu, 10 Apr 2003 03:43:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

	I have a two-level list representing a raster of gray levels.
I want to go through it fast, testing every element and at the same
time modifying certain elements following it on the same line and in
the next line. One such algorithm is known as the Floyd-Steinberg
method for converting a gray-scale image to binary. The most obvious
implementation using a double For loop seems to be extremely slow. Is
there a way to use Map or whatever?
	Thanks for any help.

floyd := Module[{cw, ch, err},
  g    = Import[fili];
  picd = Dimensions[g[[1, 1]]];   (* Actual array.    *)
  pich = picd[[1]];
  picw = picd[[2]];
  gp   = g;                                 (* Make working copy *)
  For [ ch = 1, ch < pich, ch++,
	For [ cw = 2, cw < picw, cw++,
	       If[g[[1, 1, ch, cw]] > 128, gp[[1, 1, ch, cw]] = 255,
			               gp[[1, 1, ch, cw]] =  0];
	    err = gp[[1, 1, ch, cw]] - g [[1, 1, ch, cw]];
	   g[[1, 1, ch  , cw + 1]] -= er*7/16;
	   g[[1, 1, ch + 1, cw - 1]] -= er*3/16;
	   g[[1, 1, ch + 1, cw  ]] -= er*5/16;
	   g[[1, 1, ch + 1, cw + 1]] -= er/16;
	];
  ];
    Show[gp];
    Export[filo, gp, "JPEG"];
  ]


  • Prev by Date: Re: numerical integration
  • Next by Date: Re: split a list
  • Previous by thread: Re: Integration problem
  • Next by thread: Re: Raster process