Click to See Complete Forum and Search --> : Bitmap Rotation Speckles
dangerousdave
Jan 30th, 2001, 01:19 PM
OK, I am rotating a Bitmap pixel by pixel. At angles other than multiples of 90 degrees there are white "speckles" in the image. I have heard of this problem before but never come accross it myself, is there an easy way of "despeckling" the image? What am I supposed to do?
Mad Compie
Feb 1st, 2001, 02:29 PM
I don't know, but I think this occurs because you're using Sine and Cosine (or square roots) and that gives us rounding problems, since the x and y pixels are not floating points but whole numbers.
Maybe you could use the "\" operator instead of the "/" operator.
dangerousdave
Feb 3rd, 2001, 09:43 AM
Right, I tried using the \ instead of / - no effect. I can see what you mean about the problem being in rounding though. But unfortunately my mathematic skills dont go so far as to be able to solve that problem... anyone any ideas would be appreciated.
kedaman
Feb 3rd, 2001, 10:39 AM
Youre doing it the wrong way. Instead of looping trough source images pixels and positioning them in the target, loop trough the targets pixels and find the positions in the source image. The floating numbers you get could either be rounded or used to create more smooth graphics, by dividing up all color components on the four closest pixels to the floating position, then calculate average by sumofallpixels(colorcomponent*distance to floatingpoint\cumulativedistance) for each colorcomponent, which you combine back to rgb long
HarryW
Feb 3rd, 2001, 10:42 AM
Sounds like maybe you've got a mapping problem. What you mention might occur if you were to forward-map the pixels from source to destination (ie. you take a pixel from the source and work out where it should go on the destination).
A better way to do it is inverse mapping. You take a pixel from the destination and work out where it came from on the source. This way you don't get gaps or overlaps.
dangerousdave
Feb 4th, 2001, 07:28 AM
By the way, yes you were all right, it was that I was doing source-destination mapping.
OK, so call me stupid, but how do I do the dest-source method then..?
kedaman
Feb 4th, 2001, 07:36 AM
Exactly the same way you did source-destination mapping, except that you rotate in the other direction.
dangerousdave
Feb 4th, 2001, 08:39 AM
right, here goes:
Private Function RotatePoint(x As Double, y As Double, Theta As Double) As Coord
Dim Xn 'Stores X coord using (n)ormal coordinate system
'i.e four quadrant, centre being 0,0.
Dim Yn 'Similarly for Y.
Dim Xt 'Stores ro(t)ated x point
Dim Yt 'Stores ro(t)ated y point
Dim XTemp
Dim YTemp
Xn = x - (picSource.ScaleWidth \ 2)
Yn = (-1 * y) + (picSource.ScaleHeight \ 2)
XTemp = Xn * Cos(Theta) + Yn * Sin(Theta)
YTemp = Xn * Sin(Theta) - Yn * Cos(Theta)
Xt = XTemp + (picSource.ScaleWidth \ 2)
Yt = (picSource.ScaleHeight \ 2) + (-1 * YTemp)
RotatePoint.x = Xt
RotatePoint.y = Yt
End Function
Thats what I've got. The getpixel is performed in a command button and then the function above called then the setpixel is called using the returned value from teh function above.
dangerousdave
Feb 4th, 2001, 04:38 PM
Above is the code I have. What is wrong with it then? I dont understand what you mean by destination-source mapping at all.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.