2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,5 +1,14 @@
Many image processing algorithms are defined for [[wp:Grayscale|grayscale]] (or else monochromatic) images. Extend the data storage type defined [[Basic_bitmap_storage|on this page]] to support grayscale images. Define two operations, one to convert a color image to a grayscale image and one for the backward conversion. To get luminance of a color use the formula recommended by [http://www.cie.co.at/index_ie.html CIE]:
Many image processing algorithms are defined for [[wp:Grayscale|grayscale]] (or else monochromatic) images.
L = 0.2126·R + 0.7152·G + 0.0722·B
;Task:
Extend the data storage type defined [[Basic_bitmap_storage|on this page]] to support grayscale images.
Define two operations, one to convert a color image to a grayscale image and one for the backward conversion.
To get luminance of a color use the formula recommended by [http://www.cie.co.at/index_ie.html CIE]:
<big> L = 0.2126 &times; R + 0.7152 &times; G + 0.0722 &times; B </big>
When using floating-point arithmetic make sure that rounding errors would not cause run-time problems or else distorted results when calculated luminance is stored as an unsigned integer.
<br><br>

View file

@ -9,7 +9,7 @@ sub MAIN ($filename = 'default.ppm') {
$out.say("P5\n$dim\n$depth");
for $in.slurp.ords -> $r, $g, $b {
for $in.lines.ords -> $r, $g, $b {
my $gs = $r * 0.2126 + $g * 0.7152 + $b * 0.0722;
$out.print: chr($gs min 255);
}

View file

@ -1,15 +1,34 @@
Procedure ImageGrayout(image)
Protected w, h, x, y, r, g, b, gray, color
w = ImageWidth(image)
h = ImageHeight(image)
StartDrawing(ImageOutput(image))
For x = 0 To w - 1
For y = 0 To h - 1
color = Point(x, y)
r = color & $ff
g = color >> 8 & $ff
b = color >> 16 & $ff
r = Red(color)
g = Green(color)
b = Blue(color)
gray = 0.2126*r + 0.7152*g + 0.0722*b
Plot(x, y, gray + gray << 8 + gray << 16)
Plot(x, y, RGB(gray, gray, gray)
Next
Next
StopDrawing()
EndProcedure
Procedure ImageToColor(image)
Protected w, h, x, y, v, gray
w = ImageWidth(image)
h = ImageHeight(image)
StartDrawing(ImageOutput(image))
For x = 0 To w - 1
For y = 0 To h - 1
gray = Point(x, y)
v = Red(gray) ;for gray, each of the color's components is the same
;color = RGB(0.2126*v, 0.7152*v, 0.0722*v)
Plot(x, y, RGB(v, v, v))
Next
Next
StopDrawing()

View file

@ -0,0 +1,15 @@
/*REXX program converts a RGB (red─green─blue) image to a grayscale image. */
blue= '00 00 ff'x /*define the blue color (hexadecimal).*/
@.= blue /*set the entire image to blue color.*/
width= 60 /* width of the image (in pixels). */
height= 100 /*height " " " " " */
do col=1 for width
do row=1 for height /* [↓] C2D convert char ───> decimal*/
r= left(@.col.row, 1) ; r=c2d(r) /*extract the component red & convert.*/
g=substr(@.col.row, 2, 1) ; g=c2d(g) /* " " " green " " */
b= right(@.col.row, 1) ; b=c2d(b) /* " " " blue " " */
@.col.row=d2c((.2126*r+.7152*g +.0722*b)%1) /*convert RGB number ───► grayscale. */
end /*row*/ /* [↑] D2C convert decimal ───> char*/
end /*col*/ /* [↑] x%1 is the same as TRUNC(x) */
/*stick a fork in it, we're all done. */

View file

@ -0,0 +1,14 @@
blue= "00 00 ff"x /*define the blue color (hexadecimal).*/
blue= '00 00 ff'x /*define the blue color (hexadecimal).*/
blue= '0000ff'x /*define the blue color (hexadecimal).*/
blue= '00000000 00000000 11111111'b /*define the blue color (binary). */
blue= '000000000000000011111111'b /*define the blue color (binary) */
blue= 'zzy' /*define the blue color (character). */
/*not recommended because of rendering.*/
/*where Z is the character '00'x */
/*where Y is the character 'ff'x */
/*Both Z & Y are normally not viewable*/
/*on most terminals (appear as blanks).*/

View file

@ -1,16 +0,0 @@
/*REXX program to convert a RGB image to grayscale. */
blue='00 00 ff'x /*define the blue color. */
image.=blue /*set the entire IMAGE to blue. */
width= 60 /* width of the IMAGE. */
height=100 /*height " " " */
do j=1 for width
do k=1 for height
r= left(image.j.k,1) ; r=c2d(r) /*extract red & convert*/
g=substr(image.j.k,2,1) ; g=c2d(g) /* " green " " */
b= right(image.j.k,1) ; b=c2d(b) /* " blue " " */
ddd=right(trunc(.2126*r + .7152*g + .0722*b),3,0) /*──► greyscale.*/
image.j.k=right(d2c(ddd,6),3,0) /*... and transform back.*/
end /*j*/
end /*k*/
/*stick a fork in it, we're done.*/