1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

counting black pixels in a image

Discussion in 'Visual Basic ( VB )' started by shanthi85, May 23, 2007.

  1. shanthi85

    shanthi85 New Member

    Joined:
    May 22, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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)
    	}
    }
     

Share This Page