MathGroup Archive 2003

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

Search the Archive

Re: Raster process

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40623] Re: Raster process
  • From: Steve Gray <stevebg at adelphia.net>
  • Date: Fri, 11 Apr 2003 02:03:40 -0400 (EDT)
  • References: <b7394b$p0f$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

	After I posted this I realized that the arithmetic would be
carried out in exact fractional form. Changing 7/16, etc., to decimal
results in a big improvement but it's still way slower than I would
guess it should be. Also, mysteriously, the time as measured by
Timing[floyd] shows that the execution time goes up much faster than
the total number of pixels in "g" (= length of the list). ???
	Thanks again.


On Thu, 10 Apr 2003 08:14:03 +0000 (UTC), Steve Gray
<stevebg at adelphia.net> wrote:

>	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: Integration problem
  • Next by Date: Weird Problem on an old Macintosh
  • Previous by thread: Raster process
  • Next by thread: Re: Raster process