Results 1 to 6 of 6

Thread: getpixel - setpixel question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Farmington, MN
    Posts
    76

    getpixel - setpixel question

    I am creating a 'mean' image using getpixel and setpixel from 5 images. The images are in jpg format. I'm using an array with 2 loops to go through every pixel on the image. When I use an array on just one image getpixel and then setpixel on another image it turns out fine.

    BUT, when I use the getpixel on multiple images creating mean pixels and putting these on a new image, I get a bunch of different colors on my image and it isn't clear... Even though there is no color on my 5 images which I am using to create the mean.

    The images that I'm using for this are in gray scale. I'm using a long for the getpixel and it looks like it is reading this in from the jpg in 24 bit, I think?? When I check the program the mean pixel is being computed correctly.

    Any ideas on what I need to change? Should these images read in as 256 scale? That is what I thought they would be, but they are reading in values in the millions. When I try to convert this long to grey scale I get the images in red only. Not sure what is going on, any help appreciated. Sorry I don't have the code at home, just trying to figure out what needs to be done. can post sample code tomorrow if that helps.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Farmington, MN
    Posts
    76
    Here is the portion of code which I am using. The pictures are jpg and are black and white.

    When I do the following, it works okay. When I use the sum, I get colors instead of black and white (apparently not a linear relationship).

    How do I read this in as black and white scale? It is a black and white image, but appears to be reading on a 16M scale.

    When I get the actual pixel values they are:

    Pic1
    5329233 (gray scale)
    Pic2
    4079166 (gray scale)

    Pic1 + Pic2
    4704200 (color)

    I'm trying to get a gray scale mean image.. Any help GREATLY appreciated!

    VB Code:
    1. For i = 0 To 130
    2.     For j = 0 To 220
    3.        
    4.         LX.L = ((GetPixel(Picture1.hDC, i, j))) ' + (GetPixel(Picture2.hdc, i + 20, j + 137))) / 2
    5.        
    6.         'MsgBox LX.L
    7.         'LSet Lb = LX
    8.         LGray = LX.L
    9.                
    10.         SetPixelV Picture19.hDC, i, j, LGray
    11.                
    12.     Next
    13. Next

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You need to extract the RGB values from each pixel, average them individually and then create the new color (RGB function).

    To extract RGB values use the following

    Red = lngColor And &HFF
    Green = (lngColor \ &H100) And &HFF
    Blue = (lngColor \ &H10000) And &HFF


    Have you checked out the API alphablend, transparentblt, bitblt, stretchblt and maskblt functions. I don't know if they have what you need but they do support different raster operations. Much better than having to loop through each pixel.

    Also check out this site http://EDais.earlsoft.co.uk/

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Farmington, MN
    Posts
    76
    That's not working... when I try to convert it to rgb, the image always comes out with a major red tint with values in the 0-10 range....

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Can you post your code?

    It seems to work for me, although I am testing with simple bitmaps.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Farmington, MN
    Posts
    76
    I did finally get it to work by separating the colors like you said... Do you know the formula to get this number in the 0-255 scale? It seems to be in 16M scale and is only a gray image.... I'm trying to speed it up some...

    I've used alphablend and some others, but I'm creating a mean image and standard deviation image that will be used in my programs. This won't need to be done very often, so the speed isn't real critical. Thanks!

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