Article View: sci.image.processing
Article #265Re: image processing loops: a c programming question
From: Michal Prussak
Date: Fri, 07 Aug 1992 16:18
Date: Fri, 07 Aug 1992 16:18
36 lines
1771 bytes
1771 bytes
In article <SLEHAR.92Aug7111245@kendall.bu.edu> slehar@kendall.bu.edu (Steve Lehar) writes:
>
>I have given much thought to an agonizing trade-off in image
>processing loops in c, and have not come up with a totally
>satisfactory solution- I wonder whether anyone has any good
>suggestions.
>
> yskip = 0;
> for(y=0;y<ysize;y++){
> for(x=0;x<xsize;x++){
> *(data+yskip+x) = ...
> }
> yskip += xsize;
> }
>
>Now this solution works o.k, and that is basically what I am using.
>But the code looks very messy- maybe not so bad in this example, but
>when you start adding extra inner loops like for an image convolution,
The above code is close to what I am doing - if I process pixels sequentially,
I keep a pointer to the current pixel, and increment it as I go along:
cur = data;
for (y = 0; y < ysize; y++) {
for (x = 0; x < xsize; x++, cur++) {
cur = whatever;
}
}
You can also do this if you wander around the image - to go to next or
previous pixel, just increment or decrement cur, to go to the pixel below
or above, just add or subtract the width of the bitmap. Of course, when
you travel around like this, make sure you don't step out of bounds.
Michal
Technical Details
Message-ID:
<1992Aug07.161824.198202@cs.cmu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!rochester!cantaloupe.srv.cs.cmu.edu!michalReferences:
<SLEHAR.92Aug7111245@kendall.bu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!rochester!cantaloupe.srv.cs.cmu.edu!michal From: michal+@cs.cmu.edu (Michal Prussak) Newsgroups: sci.image.processing Subject: Re: image processing loops: a c programming question Message-ID: <1992Aug07.161824.198202@cs.cmu.edu> Date: 7 Aug 92 16:18:24 GMT References: <SLEHAR.92Aug7111245@kendall.bu.edu> Distribution: sci.image.processing Organization: School of Computer Science, Carnegie Mellon Lines: 36 Nntp-Posting-Host: gs58.sp.cs.cmu.edu