Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   counting black pixels in a image (http://www.go4expert.com/forums/counting-black-pixels-image-t4398/)

 shanthi85 23May2007 07:53

counting black pixels in a image

this is the algorithm for calculating black pixels and then finding them recursively in the image...how do i change it into an Visual Basic program?

Code:

```//tests if a pixel is black /*==============================================================*/ bool IsBlack(int row, int col, LPVOID BaseAddress) {         //a pixel’s RGB val is returned         COLORREF* pPixel = ((COLORREF*) BaseAddress) + row * 640;         COLORREF curPixel = pPixel[col];         BYTE red  = GetRValue(curPixel);         BYTE blue  = GetBValue(curPixel);         BYTE green = GetGValue(curPixel);                 int black = 150; //RGB value to determine if Pixel is Black                 //returns black if RGB vals < highest acceptable black val if (red < black && blue < black && green < black)                 {return true;}         else                 {return false;} }```
Code:

```MapPattern(row, col) { /*Checks the above pixel if it is black and unmarked, if it is then the pixel is flagged into the Points structure and the MapPattern function is run with the above pixel as the parameter*/ if (Field[row–1][col] = black AND Points[row–1][col] != 1) {                 Points[row – 1][col] = 1                 MapPattern(row – 1, col)         } /* The same process checks the pixel beneath the input location (note the statement checks if the pixel is pre- existing before reentering the recursion*/ if (Field[row+1][col] = black AND Points[row+1][col] != 1)         {                 Points[row + 1][col] = 1                 MapPattern(row + 1, col)         } /*Checking the pixel left*/ if (Field[row][col–1] = black AND Points[row][col–1] != 1) {                 Points[row][col – 1] = 1                 MapPattern(row, col – 1)         } /*Checking the right pixel*/ if (Field[row][col+1] = black AND Points[row][col+1] != 1) {                 Points[row][col + 1] = 1                 MapPattern(row, col + 1)         } }```

 All times are GMT +5.5. The time now is 05:16.