Antialiasing vs ResizeImage

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Antialiasing vs ResizeImage

Post by walbus »

ResizeImage make Antialiasing simple available

But, unfortunately, this works only the image is resized

For now not making a great thing, the ask.

It is available changing ResizeImage so, Antialiasing is available also without any resizing ?

Resizing just to get Antialiasing is a bad thing

Calling ResizeImage without any resizing, but a active Antialiasing, is a simple solution without any PB syntax changing, i think ....
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Antialiasing vs ResizeImage

Post by IdeasVacuum »

Hi Walbus
Calling ResizeImage without any resizing, but a active Antialiasing,
Can't we actually do that now? Give ResizeImage the current image size such that it isn't resized but is antialiased? Worth a try....
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Antialiasing vs ResizeImage

Post by Dude »

IdeasVacuum wrote:Give ResizeImage the current image size such that it isn't resized but is antialiased?
Doesn't work.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Antialiasing vs ResizeImage

Post by nco2k »

purebasic doesnt use an anti-aliasing algorithm, it uses interpolation: https://en.m.wikipedia.org/wiki/Image_scaling

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Antialiasing vs ResizeImage

Post by walbus »

Hi folks,
no, without resizing, unfortunately, it works not

Also it looks, Nco2k is right, it's not antialiasing, it's a interpolation

In the future the canvas gadget is more and more important and a PB enhanced output with antialiasing a very good feature, i think

Especially a mixed output with the vector and the 2d library can make ugly edges, so this looks very helpfull for cosmetic

Regards werner
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Antialiasing vs ResizeImage

Post by Michael Vogel »

Why should something happen to the image without resizing it? There's no additional information to be interpreted for calculating new content.

And there's also no possibility to get a "smoother" content by doubling an existing image and reducing it again - just because og the used algorithm.

So this will "fail" also...
w=width, h=height
ResizeImage(n,w*2,h*2,#raw)
ResizeImage(n,w,h,#smooth)

So if you want to get a "better" quality for images, use bigger sizes while manipulating - this is seen especially when using text.

Short example:

Code: Select all

; Define  - - -  LoadImage Dummy Procedure by Michael Vogel

	Procedure LoadImage_(id,name.s,x,y)

		Protected z

		#VoxMin=160
		#VoxMax=800
		#VoyMin=100
		#VoyMax=600

		If FileSize(name)>0
			ProcedureReturn LoadImage(id,name,x)

		Else
			If x*y=#Null
				x=#VoxMin+Random(#VoxMax-#VoxMin)
				y=#VoyMin+Random(#VoyMax-#VoyMin)
			EndIf
			z=CreateImage(id,x,y)

			If z
				If id=#PB_Any
					id=z
				EndIf
				StartDrawing(ImageOutput(id))
				DrawingMode(#PB_2DDrawing_Gradient)
				BackColor($FFFFFF)
				GradientColor(0.3,$404040|Random(#White))
				GradientColor(0.7,#White)
				GradientColor(0.7,$404040|Random(#White))
				FrontColor($FFFFFF)
				LinearGradient(0,0,x,y)
				Box(0,0,x,y,$FFFFFF)

				DrawingMode(#PB_2DDrawing_AlphaBlend)
				For i=0 To x>>3
					Circle(Random(x),Random(y),Random(y>>3),$60000000|Random(#White))
				Next i

				StopDrawing()
				ProcedureReturn id
			EndIf

			ProcedureReturn #Null
		EndIf

	EndProcedure
	Macro LoadImage(a,b,c=0,d=0)
		LoadImage_(a,b,c,d)
	EndMacro

; EndDefine


w=400
h=500

LoadFont(0,"Arial",-160,#PB_Font_HighQuality)

LoadImage(1,#PB_Compiler_Home + "Examples/Sources/Data/PureBasic.bmp",w*2,h*2)
StartDrawing(ImageOutput(1))
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawText(0,0,"Ax%ß6@",$FF000000,0)
DrawText(0,200,"Ax%ß6@",$FFFFFFFF,0)
StopDrawing()

CopyImage(1,2)

OpenWindow(0, 0, 0, w*2,h, "-", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ResizeImage(1,w,h,#PB_Image_Raw);    nearly identical to standard size
ImageGadget(1,	0,0,		w,h,	ImageID(1))

ResizeImage(2,w,h)
ImageGadget(2,	w,0,	w,h,	ImageID(2)); smooth content by using an enlarged image

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Antialiasing vs ResizeImage

Post by Dude »

Michael Vogel wrote:there's also no possibility to get a "smoother" content by doubling an existing image and reducing it again
True, but you can create the image at double its intended height and then reduce it by half, to get anti-aliasing.

See my example here: http://www.purebasic.fr/english/viewtop ... 1&p=461549

The only trouble with that, is that the image looks "lighter" or "brighter" than it should be.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Antialiasing vs ResizeImage

Post by walbus »

@Michael,
With ResizeImage i have test this and that, the result was mostly not good

@Dude
Yep, this works, but the double resizing "eat" ever a little content

Primary for me self is each working method welcome

Regards werner
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Antialiasing vs ResizeImage

Post by Michael Vogel »

Dude wrote:See my example here: http://www.purebasic.fr/english/viewtop ... 1&p=461549
The only trouble with that, is that the image looks "lighter" or "brighter" than it should be.
You're right, but I wouldn't say that resizing images is critical in all cases. Just change your example to use a factor=2, 4 etc. and adapt the line width to the factor, the results are quite good then...

Code: Select all

#Factor=4; Quick and dirty adaption of the line width - only for demonstration
Macro CreateImage_AA(img,w,h,depth=24,color=0)
	CreateImage(img,w*#Factor,h*#Factor,depth,color)
EndMacro

Macro Circle_AA(x,y,radius,color=#PB_Default)
	For i=0 To #Factor>>1
		Circle(x*#Factor,y*#Factor,radius*#Factor+i,color)
	Next i
EndMacro

Macro LineXY_AA(x1,y1,x2,y2,color=#PB_Default)
	For i=0 To #Factor>>1
		LineXY(x1*#Factor+i,y1*#Factor,x2*#Factor+i,y2*#Factor,color)
	Next i
EndMacro

Macro Finish_AA(img)
	ResizeImage(img,ImageWidth(img)/#factor,ImageHeight(img)/#factor)
EndMacro

OpenWindow(0,0,0,680,280,"Anti-Alias Macros",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

; Normal 2D circle with line.
CreateImage(1,320,240,32,#White)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Outlined)
Circle(160,120,100,#Blue)
LineXY(0,0,320,240,#Red)
StopDrawing()

; Anti-aliased 2D circle with line.
CreateImage_AA(2,320,240,32,#White)
StartDrawing(ImageOutput(2))
DrawingMode(#PB_2DDrawing_Outlined)
Circle_AA(160,120,100,#Blue)
LineXY_AA(0,0,320,240,#Red)
StopDrawing()
Finish_AA(2) ; Required when AA drawing is done.

ImageGadget(1,10,10,320,240,ImageID(1))
ImageGadget(2,350,10,320,240,ImageID(2))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
...and for drawing nice fonts (example1, example2 etc.) there's no other possibility (which means not only more memory but also more processing time).
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Antialiasing vs ResizeImage

Post by Dude »

Thanks Michael! Looks much better.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Antialiasing vs ResizeImage

Post by walbus »

Yep, this code works fine
For demonstrating good, unfortunately, for realy using to "hungry" and non flexible

Looking here, this temporary snippet image demonstrate the problems with the vector output mixed with the other 2D output
Image
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Antialiasing vs ResizeImage

Post by nco2k »

the point of anti-aliasing is to smooth out the edges of the polygons during the composition, and not on an already finished frame. so i dont really know how you expect this to work. you could use some sort of post-processing, but it would make your image blurry as hell. the best you could do is to process the image at 2x or 4x of its size and downsample it, like Michael Vogel already pointed out. which is btw similar to how super sampling anti-aliasing works.

>> demonstrate the problems with the vector output mixed with the other 2D output
well, you cant expect edge free vector graphics to look good on a low resolution pixel background. this "problem" exists since the invention of computers. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Antialiasing vs ResizeImage

Post by walbus »

Yep, its so you say
Its also not a realy problem, with higher resulutions this problems gone more and more in the future
Post Reply