Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

data overwrite not as expected...prob simple error

The first code works. It changes my picture to all green. But when I apply selection criteria, as in the second snippet, it doesn't seem to overwrite the values, at all! What's the problem?

Code that works (changes all data elements to green - Hue value of 60 (multiplied by two in later conversion):
int height = HImage->height;
            int width = HImage->width;
            int step = HImage->widthStep;
            uchar*p=(uchar*)HImage->imageData;

            for (int i=0; i< height; i++)
            {
            for (int j=0; j< width; j++)
            {

                p[j]=60; //green / by 2
         
            }
                p+=step; //go to next row
            }

Code that doesn't work with selection criteria:

int height = HImage->height;
            int width = HImage->width;
            int step = HImage->widthStep;
            uchar*p=(uchar*)HImage->imageData;

            for (int i=0; i< height; i++)
            {
            for (int j=0; j< width; j++)
            {
                if ((p[j]>115)   &&(p[j]<125))  //if hue value in blue range
                {

                MessageBox(NULL,"Found red!","Error",MB_OK);

                p[j]=60; //green / by 2
                }
              else
               {
                    //nada
                }
            }
                p+=step; //go to next row
            }
:
Thanks to anyone who can help....WLE



0
Wanderinglazyeye
Asked:
Wanderinglazyeye
2 Solutions
 
Infinity08Commented:
Do you get message boxes ?
0
 
jkrCommented:
Chances are that there simply is not data that falls into the range [115;125], try to widen it a bit.  BTW, did you mean to

                if ((p[j]>=115)   &&(p[j]<=125))  //if hue value in blue range

?
0
 
WanderinglazyeyeAuthor Commented:
Ok, widening the range got it! We now have a digital color extraction filter. I didn't think it was that simple.

Thanks WLE

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now