Adding Antialiasing To An Image

Miscellaneous Forums/General Discussion/Adding Antialiasing To An Image

Ok, I have a picture of a ball which I drew in paint. It's very basic, light red with a darker red border. Is there any software that can antialiase (or whatever the proper term is) the image?

I have Paintshop Pro 8 but I've tried numerous things, none of which work. I don't fancy working out the right colours and doing it by hand either :D

Thanks,
Matthew

Normally you would just make the image at double ( or quadruple ) the size you want it, and then resize it. This lets the inbuilt image filters soften the edges. You could try doubling and then halving the resolution?

Microsoft Photo editor, (Part of Windows), just "Soften" the image

if you want to do it by hand, you don't have to work out the right colors, just set the brush to 50% transparent. then 25% or more... test around and find what you like.

Thanks for the replies.

I tried doubling the image but it didn't seem to work. I think I might have gotten rid of Photo Editor so i'll have to hunt out my XP disk and get it back. And I'll try what you you suggested DampeS8N.

You can't really add antialiasing to an existing image, you either need to redraw it at double size, or haev the original vector information handy.

Adding soften works to a degree, but doesn't look anywhere near as neat as actual antialiasing. Soften=smudging, basically.

You can add AA to anything by hand. it just takes time... the bigger it is, the longer it takes.. at the same time, the higher the rez the less important it is... on a website, it is important, and low enough to do by hand.

Redraw the image :) or scale 2x-4x and redraw edges that need AA and finally scale it down to needed size.
Or use program that uses some kind of edge detection and scales image better up. And again scale down to final image.

This antialias function created by Leadwerks, might do the trick :-)
taken from here:
http://www.blitzbasic.co.nz/Community/posts.php?topic=39429

Just change the path to your image:

Graphics3D 800,600,32,2

image=LoadImage("YourImageHere.bmp")


DrawBlock image,0,0

Color 0,0,0

Text 400,50,"Image Not Antialiased, press space to antialias it",True,True


Flip
Repeat

	If KeyDown(1)
		End
	EndIf

Until KeyHit(57)
FlushKeys

DrawBlock image,0,0

Text 400,50,"Antialiasing.... please wait",True,True

Flip

AntiAliasBuffer(ImageBuffer(image),ImageWidth(image)-1,ImageHeight(image)-1,1,40)


DrawBlock image,0,0

Text 400,50,"Image Antialiased!",True,True

Flip
Repeat

	If KeyDown(1)
		End
	EndIf

Until KeyHit(57)
FlushKeys



;function by Leadwerks: www.leadwerks.com
;taken from here: 
;http://www.blitzbasic.co.nz/Community/posts.php?topic=39429
Function AntiAliasBuffer(buffer,w,h,passes=1,threshhold=20)
gfxbuffer=GraphicsBuffer()
SetBuffer buffer
LockBuffer buffer
For p=1 To passes
	For x=0 To w-1
		For y=0 To h-1
			hue=ReadPixelFast(x,y)
			r=Red(hue)
			g=Green(hue)
			b=Blue(hue)
			count=BottomLeftPixelsAntialiased(buffer,w,h,x,y,threshhold)
			For n=1 To count
				perc#=Float(n)/Float(count)
				hue=ReadPixelFast(x-n,y)
				lr=Red(hue)*perc+r*(1.0-perc)
				lg=Green(hue)*perc+g*(1.0-perc)
				lb=Blue(hue)*perc+b*(1.0-perc)
				WritePixelFast x-n,y,RGB(lr,lg,lb)
				Next
			count=BottomRightPixelsAntialiased(buffer,w,h,x,y,threshhold)
			For n=1 To count
				perc#=Float(n)/Float(count)
				hue=ReadPixelFast(x+n,y)
				lr=Red(hue)*perc+r*(1.0-perc)
				lg=Green(hue)*perc+g*(1.0-perc)
				lb=Blue(hue)*perc+b*(1.0-perc)
				WritePixelFast x+n,y,RGB(lr,lg,lb)
				Next
			count=VerticalBottomLeftPixelsAntialiased(buffer,w,h,x,y,threshhold)
			For n=1 To count
				perc#=Float(n)/Float(count)
				hue=ReadPixelFast(x,y-n)
				lr=Red(hue)*perc+r*(1.0-perc)
				lg=Green(hue)*perc+g*(1.0-perc)
				lb=Blue(hue)*perc+b*(1.0-perc)
				WritePixelFast x,y-n,RGB(lr,lg,lb)
				Next
			count=VerticalBottomRightPixelsAntialiased(buffer,w,h,x,y,threshhold)
			For n=1 To count
				perc#=Float(n)/Float(count)
				hue=ReadPixelFast(x,y+n)
				lr=Red(hue)*perc+r*(1.0-perc)
				lg=Green(hue)*perc+g*(1.0-perc)
				lb=Blue(hue)*perc+b*(1.0-perc)
				WritePixelFast x,y+n,RGB(lr,lg,lb)
				Next
			Next
		Next
	Next
UnlockBuffer buffer
SetBuffer gfxbuffer
End Function

Function BottomLeftPixelsAntialiased(buffer,w,h,x,y,threshhold)
If x=0 Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
Repeat
	found=False
	hue=ReadPixelFast(x-1,y)
	lr=Red(hue)
	lg=Green(hue)
	lb=Blue(hue)
	If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
		If y<h
			hue=ReadPixelFast(x-1,y+1)
			blr=Red(hue)
			blg=Green(hue)
			blb=Blue(hue)
			If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
				found=True
				EndIf				
			EndIf
		EndIf
	If found
		count=count+1
		Else
		Exit
		EndIf
	If x=0 Exit
	x=x-1
	Forever
Return count
End Function

Function BottomRightPixelsAntialiased(buffer,w,h,x,y,threshhold)
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
If x=w Return
Repeat
	found=False
	hue=ReadPixelFast(x+1,y)
	lr=Red(hue)
	lg=Green(hue)
	lb=Blue(hue)	
	If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
		If y<h
			hue=ReadPixelFast(x+1,y+1)
			blr=Red(hue)
			blg=Green(hue)
			blb=Blue(hue)
			If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
				found=True
				EndIf				
			EndIf
		EndIf
	If found
		count=count+1
		Else
		Exit
		EndIf
	If x=w-1 Exit
	x=x+1
	Forever
Return count
End Function

Function VerticalBottomLeftPixelsAntialiased(buffer,w,h,x,y,threshhold)
If y=0 Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
Repeat
	found=False
	hue=ReadPixelFast(x,y-1)
	lr=Red(hue)
	lg=Green(hue)
	lb=Blue(hue)
	If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
		If x>0
			hue=ReadPixelFast(x-1,y-1)
			blr=Red(hue)
			blg=Green(hue)
			blb=Blue(hue)
			If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
				found=True
				EndIf				
			EndIf
		EndIf
	If found
		count=count+1
		Else
		Exit
		EndIf
	If y=0 Exit
	y=y-1
	Forever
Return count
End Function

Function VerticalBottomRightPixelsAntialiased(buffer,w,h,x,y,threshhold)
If y=h Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
Repeat
	found=False
	hue=ReadPixelFast(x,y+1)
	lr=Red(hue)
	lg=Green(hue)
	lb=Blue(hue)
	If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
		If x>0
			hue=ReadPixelFast(x-1,y+1)
			blr=Red(hue)
			blg=Green(hue)
			blb=Blue(hue)
			If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
				found=True
				EndIf				
			EndIf
		EndIf
	If found
		count=count+1
		Else
		Exit
		EndIf
	If y=h Exit
	y=y+1
	Forever
Return count
End Function


Function rgb(r,g,b)
	Return b + g Shl 8 + r Shl 16
End Function


Function Red(rgb)
	Return rgb Shr 16
End Function

Function Green(rgb)
	Return rgb Shr 8 - ((rgb Shr 16) Shl 8)
End Function

Function Blue(rgb)
	Return rgb-red(rgb) Shl 16-green(rgb) Shl 8
End Function



problem with doubling then halving is that the software may do this without any antialiasing, so it may be better to reduce by *almost* half, but not quite, or when it's large, shift it by one pixel so when it shrinks it has to anti-alias the edges. However, yeah draw big then shrink is best, or use a 3D pacakge or DTP package (Corel/Publisher) and then export with anti-alias set on.

Depends if the software offers different types of interpolation/filtering

Maybe make it 5 times bigger then scale it down to 3 times then to 2 times?