Gamma test

For finished programs
Post Reply
User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Gamma test

Post by Dutchman » Wed Sep 11, 2019 4:54 pm

To get gradations in color or black-and-white in the desired way on the display, it is important to know the gamma of the transfer function: RGB input to light output.
See https://en.wikipedia.org/wiki/Gamma_correction.
In principle, a test of the actual gamma can easily be performed. See http://www.lagom.nl/lcd-test/gamma_calibration.php
If pixels or lines next to each other in turn get zero or maximum color, the pixels will merge visually at some distance into a color with half the maximum value. If you then embed this pattern in a field with an even color, you can adjust the size of the programmed color so that the displayed color in the overall image appears to be visually even. The gamma can then be calculated from the ratio between the set color value and half the maximum value.
The accompanying test images are based on this principle.
In the attached zip-file are two testimages.
Images.zip
(108.5 KiB) Downloaded 20 times
The file "gamma-test-1.jpg" contains a black and white version with lines that are black or maximum white, embedded in fields with various grey values determined by the indicated gamma.
The file "gamma-test-2.jpg" contains a color version with three different maximum values. On the Mac, around the gamma value 2.2, the coloured bars should appear uniform in color. An enlarged part of that test image is:
Enlarged crop from gamma-test-2.JPG
Enlarged crop from gamma-test-2.JPG (63.13 KiB) Viewed 901 times
It is important that the test images are displayed without post-processing and without anti-aliasing.
In the accompanying program this is achieved by loading the test images with a scale equal to Scale=1/SCRSCALE.

Code: Select all

'Gamma test
'show images with gamma test patterns
'by "Dutchman" Ton Nillesen, September 2019
'
'==== User settings
Wait=5 ' delay between pictures
Dir$="/My stuff/Images/"
DIM Img() = Dir$+"gamma-test-1.jpg", Dir$+"gamma-test-2.png"
Scale=1/SCRSCALE ' picture directlly written to pixels?
PRINT "Scale =";scale
'
'=== Main
nn=SIZE OF Img
'--- load images
FOR n=0 TO nn-1
IF NOT FILE EXISTS Img(n)
  PRINT "File """+img(n)+""" not found.": STOP
ENDIF
DRAW IMAGE Img(n) 0 0 scale
DELAY Wait
NEXT
Both images are loaded one after the other with a waiting time.
In the future I certainly will program a test image with a slider or buttons for setting the correct gamma. For that I would like to have a "DRAW PIXEL TO x, y" command to be able to easily draw lines at the pixel level.

On the Mac, the gamma can be set with
Apple> System Preferences> Displays> Color> Calibrate> Gamma
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Gamma test

Post by kibernetik » Wed Sep 11, 2019 5:44 pm

Drawing functions on pixel level are currently not planned.
It is supposed that user will create his own pixel-level drawing procedures.

Yes, if image has scale 1 (72 dpi) then drawing it in 1/scrscale scale draws it pixel-to-pixel to the screen.

User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Gamma test

Post by Dutchman » Thu Sep 12, 2019 12:46 pm

kibernetik wrote:
Wed Sep 11, 2019 5:44 pm
Drawing functions on pixel level are currently not planned.
I understand that, but only extending the DRAW PIXEL x, y command to DRAW PIXEL x, y [, x2, y2] would help and care a lot about the speed:
.
Speed test lines drawn in points and pixels.JPG
Speed test lines drawn in points and pixels.JPG (29.63 KiB) Viewed 888 times

Code: Select all

'speed test pixel line drawing
CLS
sw sh =SCRSIZE|2
PRINT "Width=";sw;" Heigth=";sh
'
'--- draw point lines
DRAWCLEAR 0,0,0
DRAWCOLOR 1,1,1
TIMER SET
FOR i=0 to sh STEP 2
  DRAW LINE 0,i,sw,i
NEXT
t1=TIMER GET
PRINT "Point-lines drawn in "+STRTEXT(t1,"0.000")+" seconds."
'
'--- clear pixel area
DRAW COLOR 0,0,0
DRAW FRECT 0,0,sw/2,sh/2
'
'--- draw pixel lines
DRAWCOLOR 1,1,1
TIMER SET
FOR i=0 to sh STEP 2
  FOR n=0 TO sw
    DRAW PIXEL n,i
  NEXT
NEXT
t2=TIMER GET
PRINT "Pixel-lines drawn in "+STRTEXT(t2,"0.000")+" seconds."
PRINT "System command (points) is "+STRTEXT(t2/t1 "0")\
      +" times faster then user function (pixels)."
END
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Gamma test

Post by kibernetik » Thu Sep 12, 2019 1:16 pm

Yes, idea to extend already existing function is a good idea! Thank you!

User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Gamma test

Post by Dutchman » Fri Sep 20, 2019 7:59 am

Speed tests on line draw function with extended DRAWPIXEL command gives varying results, but the speed is always hundreds of times faster than the function with the old one. :lol:

Code: Select all

'speed test pixel line drawing
CLS
sw sh =SCRSIZE|2
PRINT "Width=";sw;" Heigth=";sh
'
'--- draw point lines
DRAWCLEAR 0,0,0
DRAWCOLOR 1,1,1
TIMER SET
FOR i=0 to sh STEP 2
  DRAW LINE 0,i,sw,i
NEXT
t1=TIMER GET
PRINT "Point-lines drawn in "+STRTEXT(t1,"0.000")+" seconds."
'
'--- clear pixel area
DRAW COLOR 0,0,0
DRAW FRECT 0,0,sw/2,sh/2
'
'--- draw pixel lines OLD
DRAWCOLOR 1,1,1
TIMER SET
FOR i=0 to sh STEP 2
  FOR n=0 TO sw
    DRAW PIXEL n,i
  NEXT
NEXT
t2=TIMER GET
DELAY 0.5
DRAWCLEAR 0,0,0
'--- draw pixel lines NEW
DRAW COLOR 0,0,0
DRAW FRECT 0,0,sw/2,sh/2
DRAWCOLOR 1,1,1
TIMER SET
FOR i=0 to sh STEP 2
  DRAWPIXEL 0,i,sw,i
NEXT
t3=TIMER GET
PRINT "Pixel-lines drawn in "+STRTEXT(t2,"0.000")+" seconds."
PRINT "System command (points) is "+STRTEXT(t2/t1 "0")\
      +" times faster then user function (pixels)."
PRINT: PRINT "New DRAWPIXEL command is "+STRTEXT(t2/t3,"0.0")\
              +" times faster."
END
.
Speed test DRAWPIXEL.JPG
Speed test DRAWPIXEL.JPG (32.58 KiB) Viewed 877 times
It is still a long way to go

Post Reply