Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:55:59+00:00 2026-06-08T10:55:59+00:00

I’m working on some image processing app for an iOS and thresholding is really

  • 0

I’m working on some image processing app for an iOS and thresholding is really a huge bottleneck. So I’m trying to optimize it using NEON. Here is the C version of function. Is there any way to rewrite this using NEON (unfortunately I have absolutely no experience in this) ?

static void thresh_8u( const Image& _src, Image& _dst, uchar thresh, uchar maxval, int type ) {
    int i, j;
    uchar tab[256];
    Size roi = _src.size();
    roi.width *= _src.channels();

    memset(&tab[0], 0, thresh);
    memset(&tab[thresh], maxval, 256-thresh);

    for( i = 0; i < roi.height; i++ ) {
        const uchar* src = (const uchar*)(_src.data + _src.step*i);
        uchar* dst = (uchar*)(_dst.data + _dst.step*i);
        j = 0;

        for(; j <= roi.width; ++j) {
            dst[j] = tab[src[j]];
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:56:01+00:00Added an answer on June 8, 2026 at 10:56 am

    It’s actually pretty easy, if you can make sure your rows are always a multiple of 16 bytes wide, because the compiler (clang) has special types representing the NEON vector registers, and knows how to apply the normal C operators to them. Here’s my little test function:

    #ifdef __ARM_NEON__
    
    #include <arm_neon.h>
    
    void computeThreshold(void *input, void *output, int count, uint8_t threshold, uint8_t highValue) {
        uint8x16_t thresholdVector = vdupq_n_u8(threshold);
        uint8x16_t highValueVector = vdupq_n_u8(highValue);
        uint8x16_t *__restrict inputVector = (uint8x16_t *)input;
        uint8x16_t *__restrict outputVector = (uint8x16_t *)output;
        for ( ; count > 0; count -= 16, ++inputVector, ++outputVector) {
            *outputVector = (*inputVector > thresholdVector) & highValueVector;
        }
    }
    
    #endif
    

    This operates on 16 bytes at a time. A uint8x16_t is a vector register containing 16 8-bit unsigned ints. The vdupq_n_u8 returns a vector uint8x16_t filled with 16 copies of its argument.

    The > operator, applied to two uint8x16_t values, does 16 comparisons between pairs of 8-bit unsigned ints. Where the left input is greater than the right input, it returns 0xff (which is different from a normal C >, which just returns 0x01). Where the left input is less than or equal to the right input, it returns 0. (It compiles into the VCGT.U8 instruction.)

    The & operator, applied to two uint8x16_t values, computes the boolean AND of 128 pairs of bits.

    The loop compiles to this in a release build:

    0x6e668:  vldmia r2, {d4, d5}
    0x6e66c:  subs   r0, #16
    0x6e66e:  vcgt.u8 q10, q10, q8
    0x6e672:  adds   r2, #16
    0x6e674:  cmp    r0, #0
    0x6e676:  vand   q10, q10, q9
    0x6e67a:  vstmia r1, {d4, d5}
    0x6e67e:  add.w  r1, r1, #16
    0x6e682:  bgt    0x6e668
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.