|
-
Jan 28th, 2003, 09:24 PM
#1
Thread Starter
Lively Member
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.
-
Jan 30th, 2003, 02:37 PM
#2
Thread Starter
Lively Member
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:
For i = 0 To 130
For j = 0 To 220
LX.L = ((GetPixel(Picture1.hDC, i, j))) ' + (GetPixel(Picture2.hdc, i + 20, j + 137))) / 2
'MsgBox LX.L
'LSet Lb = LX
LGray = LX.L
SetPixelV Picture19.hDC, i, j, LGray
Next
Next
-
Jan 30th, 2003, 04:34 PM
#3
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/
-
Jan 30th, 2003, 06:30 PM
#4
Thread Starter
Lively Member
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....
-
Jan 31st, 2003, 12:22 AM
#5
Can you post your code?
It seems to work for me, although I am testing with simple bitmaps.
-
Jan 31st, 2003, 08:49 AM
#6
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|