We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I'm searching for a fast way to substract a dark image from another image. If the dark image pixel value is greater than the corresponding image pixel, the resulting image pixel should be zero. Otherwise, it should be simply substracted.
Are there special functions for doing this job?
I got an AT91SAM9260 processor and the image data is 10bit depth, laying in a 16-bit array.
Many thank, Stefan
enum { // max value in dark image, which also represents // most negative result from *img - *dark OFFSET = 100, }; // Switch from two-dimensional representation to a // linear array, to simplify loop. uint16_t* pimg = (uint16_t*)image; uint16_t* pdark = (uint16_t*)dark_image; uint16_t *pend = pimg + width*height; const uint16_t lut[1024+offset] = { // Clamp all negative values - i.e image darker than // the dark image, to zero. Note correlation with // OFFSET constant above. 0,0,0,0,0,..., 1,2,3,4,5,6 }; while (pimg < pend) { *pimg++ = lut[OFFSET + *pimg-*pdark++]; *pimg++ = lut[OFFSET + *pimg-*pdark++]; *pimg++ = lut[OFFSET + *pimg-*pdark++]; *pimg++ = lut[OFFSET + *pimg-*pdark++]; }
Normally with a bit of loop unroll. If the pixel count isn't evenly divisable by the unroll factor, then it is often good to allocate a couple of dummy pixels at the end of the image, and convert these too.