Results 1 to 3 of 3

Thread: is pixel an outline pixel

  1. #1

    Thread Starter
    Member NTShpikho's Avatar
    Join Date
    Oct 2023
    Posts
    38

    is pixel an outline pixel

    Code:
     Public Shared Function isOutLine(ByVal xPos As Integer, ByVal Ypos As Integer, ByVal image As Bitmap, ByVal bias As Integer) As Boolean
    
            Dim result As Boolean = False
            Dim change As Byte = 0
            If xPos > 0 And xPos < image.Width - 1 And Ypos > 0 And Ypos < image.Height - 1 Then
                Dim color1, color2, color3, color4, color5, color6, color7, color8, color9 As Color
                color1 = image.GetPixel(xPos - 1, Ypos - 1)
                color2 = image.GetPixel(xPos, Ypos - 1)
                color3 = image.GetPixel(xPos + 1, Ypos - 1)
                color7 = image.GetPixel(xPos - 1, Ypos + 1)
                color8 = image.GetPixel(xPos, Ypos + 1)
                color9 = image.GetPixel(xPos + 1, Ypos + 1)
                color4 = image.GetPixel(xPos - 1, Ypos)
                color6 = image.GetPixel(xPos + 1, Ypos)
                color5 = image.GetPixel(xPos, Ypos)
    
                If (CType(color5.R, Integer) > CType(color4.R, Integer) - bias) And (CType(color5.R, Integer) < CType(color4.R, Integer) + bias) Then
                    change += 1
    
                End If
                If (CType(color5.G, Integer) > CType(color4.G, Integer) - bias) And (CType(color5.G, Integer) < CType(color4.G, Integer) + bias) Then
                    change += 1
    
                End If
                If (CType(color5.B, Integer) > CType(color4.B, Integer) - bias) And (CType(color5.B, Integer) < CType(color4.B, Integer) + bias) Then
                    change += 1
    
                End If
                If (CType(color5.R, Integer) > CType(color8.R, Integer) - bias) And (CType(color5.R, Integer) < CType(color8.R, Integer) + bias) Then
                    change += 1
    
                End If
                If (CType(color5.G, Integer) > CType(color8.G, Integer) - bias) And (CType(color5.G, Integer) < CType(color8.G, Integer) + bias) Then
                    change += 1
    
                End If
                If (CType(color5.B, Integer) > CType(color8.B, Integer) - bias) And (CType(color5.B, Integer) < CType(color8.B, Integer) + bias) Then
                    change += 1
    
                End If
            End If
    
            'Dim sumR, sumG, sumB As Integer
    
            'sumR = (CType(color1.R, Integer) + CType(color2.R, Integer) + CType(color3.R, Integer))
            'sumR -= (CType(color7.R, Integer) + CType(color8.R, Integer) + CType(color9.R, Integer))
            ''sumG = (CType(color7.R, Integer) + CType(color8.R, Integer) + CType(color9.R, Integer))
            ''sumG -= (CType(color1.G, Integer) + CType(color2.G, Integer) + CType(color3.G, Integer))
            ''sumB = (CType(color1.B, Integer) + CType(color2.B, Integer) + CType(color3.B, Integer))
            ''sumB -= (CType(color7.B, Integer) + CType(color8.B, Integer) + CType(color9.B, Integer))
            'sumR = Abs(sumR)
            ''sumG = Abs(sumG)
            ''sumB = Abs(sumB)
            ''Dim sumR2, sumG2, sumB2 As Integer
            ''sumR2 = (CType(color1.R, Integer) + CType(color4.R, Integer) + CType(color7.R, Integer))
            ''sumG2 = (CType(color1.G, Integer) + CType(color4.G, Integer) + CType(color7.G, Integer))
            ''sumB2 = (CType(color1.B, Integer) + CType(color4.B, Integer) + CType(color7.B, Integer))
            ''sumR2 -= (CType(color3.R, Integer) + CType(color6.R, Integer) + CType(color9.R, Integer))
            ''sumG2 -= (CType(color3.G, Integer) + CType(color6.G, Integer) + CType(color9.G, Integer))
            ''sumB2 -= (CType(color3.B, Integer) + CType(color6.B, Integer) + CType(color9.B, Integer))
            ''sumR2 = Abs(sumR2)
            ''sumG2 = Abs(sumG2)
            ''sumB2 = Abs(sumB2)
    
            ''sumR2 = color1.R + color4.R + color7.R
            ''sumG2 = color1.G + color4.G + color7.G
            ''sumB2 = color1.B + color4.B + color7.B
            ''sumR2 -= color3.R + color6.R + color9.R
            ''sumG2 -= color3.G + color6.G + color9.G
            ''sumB2 -= color3.B + color6.B + color9.B
            If change = 6 Then
                result = True
            End If
            Return result
        End Function
    down that coffee slug

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,657

    Re: is pixel an outline pixel

    Is this a working code snippet? What does it do, and is that what it's supposed to do?

  3. #3

    Thread Starter
    Member NTShpikho's Avatar
    Join Date
    Oct 2023
    Posts
    38

    Re: is pixel an outline pixel

    Quote Originally Posted by .paul. View Post
    Is this a working code snippet? What does it do, and is that what it's supposed to do?
    the method checks a specific pixel at the (x,y) position of a bitmap, and checks if said pixel is a part of an outline (contour) of
    an object.
    down that coffee slug

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width