Re: Fast Image access for binarization



Siddharth,

you may at least want to reduce the width*height in the for loop. On
each iteration you're doing a multiplication that is not really needed
(assuming the compiler doesn't optimize this out).

Perhaps you can also try

int image[512*512];
int *pixel = image;
int *end = &image[512*512];

while (pixel!=end)
{
*pixel++ = *pixel>threshold;
}

and see if this makes a difference. Note that some compilers may not
compile the *pixel++ correctly. Also if you can make the 'threshold' a
constant that may help a little too.

You may also find that adding a

if (*pixel)
*pixel++ = *pixel>threshold;
else
pixel++;

may also make a difference depending on how your CPU caches read versus
write memory statements. Note that uneeded writes can sometimes be more
expensive than a read and comparison from a cache ... but this is very
CPU dependant.

Hope this helps!

STeven.
http://www.roborealm.com/
Where robots live ...

.



Relevant Pages

  • Re: code optimization
    ... > void myrotate(int dim, pixel *src, pixel *dst) ... the compiler that the two ranges don't overlap. ... Hmm, not much that can be done here. ... to the row in the inner loop in order not to redo this computation for ...
    (comp.lang.c)
  • Re: Operation recomputation
    ... I in a loop have to compare ... it everytime does the shifting from the original foo value or if it ... The answer depends on whether your compiler can recognize the common ... example, I use that 10 times for each pixel I process, and ...
    (comp.lang.c)
  • Re: Operation recomputation
    ... it everytime does the shifting from the original foo value or if it ... The answer depends on whether your compiler can recognize the common ... in my case it's not a micro optimization since for my ... example, I use that 10 times for each pixel I process, and ...
    (comp.lang.c)
  • Re: Fine tuning register use with C# ?
    ... it will be probably more efficient to pack the RGB values of a pixel ... Software Design Engineer, CLR JIT Compiler ... > smart the JITer is (optimizing the switch statements, ... >> But you HAVE to attach the process with debugging to see this - normal ...
    (microsoft.public.dotnet.framework.performance)
  • Re: High CPU usage for basic frame processing
    ... consecutive threshold crossings, it counts any pixel above and below ... tricks with the assembly code and speed it up too. ... intensity for a single pixel at once But it does ... And that's something that a compiler is most likely not going to be ...
    (microsoft.public.win32.programmer.directx.video)