C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Scanning intensity value of pixel from binary image Posted by labby on 9 Sept 2006 at 3:11 AM
Hi,

I want to scan intensity value of pixel for binary image. Here is the code that I build.

byte* p = (byte*)imgData.Scan0.ToPointer();
int i = 0;

for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
{

if (*p != 0)// white
{
i++;
}

else
{
i = 0;
}
}
++p;
}

p += srcOffset;

}

if (i >= 10)

resultScan = "PASS";

else
resultScan = "FAIL";


Here, I want to make it;
If there are any intensity values of pixel other than zero, and the total of that pixel is more or similar to 10, it will return PASS. Otherwise it will return FAIL. Means, it will return PASS if I put object in the field of view and returns FAIL if no object in the field of view.

However, it not gives right answer. It just give FAIL statement for both condition. Im sure this is not the mistake from type of image input but something wrong with the condition of if else. Could any body help me please to check where the mistakes are? Please ask me if my question is not clear. Thanks.

Report
Re: Scanning intensity value of pixel from binary image Posted by Pruyque on 9 Sept 2006 at 6:16 AM
: Hi,
:
: I want to scan intensity value of pixel for binary image. Here is the code that I build.
:
: byte* p = (byte*)imgData.Scan0.ToPointer();
: int i = 0;
:         
:                 for (int y = 0; y < height; y++)
:                 {
:                     for (int x = 0; x < width; x++)
:                     {
:                         {
: 
:                             if (*p != 0)// white
:                             {
:                                 i++;
:                             }
: 
:                             else 
:                             {

:                                 i = 0;

:                             }
:                         }
:                         ++p;
:                     }
: 
:                     p += srcOffset;
:                    
:                 }
: 
:                 if (i >= 10)
: 
:                     resultScan = "PASS";
: 
:                 else
:                     resultScan = "FAIL";
: 
: 

: Here, I want to make it;
: If there are any intensity values of pixel other than zero, and the total of that pixel is more or similar to 10, it will return PASS. Otherwise it will return FAIL. Means, it will return PASS if I put object in the field of view and returns FAIL if no object in the field of view.
:
: However, it not gives right answer. It just give FAIL statement for both condition. Im sure this is not the mistake from type of image input but something wrong with the condition of if else. Could any body help me please to check where the mistakes are? Please ask me if my question is not clear. Thanks.
:
:

If (*p == 0) you reset 'i' to zero. If you want to count how many pixels are not 0, don't set 'i' to zero if it is (just do nothing)...

For instance, if the last *p you check is zero, 'i' will be zero if you check it against 10, and this is not what you want...

Hope this helps,

Pruyque
Report
Re: Scanning intensity value of pixel from binary image Posted by labby on 9 Sept 2006 at 6:30 AM
Hi,

Sorry for that silly mistake. Actually I not put that code initially, but when I got stuck, I just put any code to see what happen than. This is my actual code.

byte* p = (byte*)imgData.Scan0.ToPointer();
int i = 0;


for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (*p != 0)// white
{
i++;
}
p++;
}
p += srcOffset;
}

if (i >= 10)

resultScan = "PASS";

else
resultScan = "FAIL";


Here --> if (*p != 0)// white
when I change the value of 0 to 255, the answer are still same
--> PASS. Im confuse where are the mistake.

Report
Re: Scanning intensity value of pixel from binary image Posted by Pruyque on 10 Sept 2006 at 8:15 AM
: Hi,
:
: Sorry for that silly mistake. Actually I not put that code initially, but when I got stuck, I just put any code to see what happen than. This is my actual code.
:
: byte* p = (byte*)imgData.Scan0.ToPointer();
:                 int i = 0;
:             
:             
:                 for (int y = 0; y < height; y++)
:                 {
:                     for (int x = 0; x < width; x++)
:                     {
:                             if (*p != 0)// white
:                             {
:                                 i++;
:                             }
:                             p++;
:                     }
:                     p += srcOffset;               
:                 }
: 
:                 if (i >= 10)
: 
:                     resultScan = "PASS";
: 
:                 else
:                     resultScan = "FAIL";
: 
: 

: Here --> if (*p != 0)// white
: when I change the value of 0 to 255, the answer are still same
: --> ?PASS?. I?m confuse where are the mistake.
:
:
Hmmm, what is scrOffset? (I think it should be the stride of the image minus the width of the image.)

You could just print the values that you examine, if the first few look good, but later on you get garbage, it might be you've miscalculated scrOffset... I can't think of anything else being wrong at the moment...

Oh, and please use the [ code ] tags (without the spaces), it makes reading code much easier for us.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.