Grayscale image: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 3 users not shown)
Line 1:
{{task|Image processing}}[[Category:Raster graphics operations]]
 
Many image processing algorithms are defined for [[wp:Grayscale|grayscale]] (or else monochromatic) images.
Line 644:
 
There is a test program, which can be compiled and run as follows:
<pre>$ patscc -std=gnu2x -g -O2 -DATS_MEMALLOC_LIBC -DATS BITMAP_GRAYSCALE_TASK_TEST bitmap{,_{write_ppm,grayscale}_grayscale}_task.{s,d}ats -lm
$ ./a.out</pre>
 
Line 1,327:
animage = gray
call output_ppm(an_unit, animage)</syntaxhighlight>
 
=={{header|Fōrmulæ}}==
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
In '''[https://formulae.org/?example=Grayscale_image this]''' page you can see the program(s) related to this task and their results.
 
=={{header|FreeBASIC}}==
Line 1,413 ⟶ 1,405:
{{output}}
[[File:Color to Grayscale.png]]
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Grayscale_image}}
 
'''Solution'''
 
Note the use of the dot product in the calculation of the gray level.
 
[[File:Fōrmulæ - Grayscale image 01.png]]
 
'''Test case'''
 
[[File:Fōrmulæ - Grayscale image 02.png]]
 
[[File:Fōrmulæ - Grayscale image 03.png]]
 
=={{header|Go}}==
Line 2,001 ⟶ 2,009:
<syntaxhighlight lang="matlab">function [grayImage] = colortograyscale(inputImage)
grayImage = rgb2gray(inputImage);</syntaxhighlight>
 
=={{header|MiniScript}}==
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
greyedColor = function(colr)
clist = color.toList(colr)
lum = [0.2126, 0.7152, 0.0722]
red = clist[0] * lum[0]
green = clist[1] * lum[1]
blue = clist[2] * lum[2]
grey = red + green + blue
return color.fromList([grey, grey, grey, clist[3]])
end function
 
toGreyScale = function(img)
greyImg = Image.create(img.width, img.height)
for x in range(0, img.width - 1)
for y in range(0, img.height - 1)
greyed = greyedColor(img.pixel(x, y))
greyImg.setPixel x, y, greyed
end for
end for
return greyImg
end function
 
clear
 
// The turtle and color wheel images are included with MiniMicro
turtle = file.loadImage("/sys/pics/animals/turtle.png")
greyTurtle = toGreyScale(turtle)
gfx.drawImage turtle, 0, 0
gfx.drawImage greyTurtle, turtle.width, 0
 
colorWheel = file.loadImage("/sys/pics/ColorWheel.png")
greyWheel = toGreyScale(colorWheel)
gfx.drawImage colorWheel, 0, 320
gfx.drawImage greyWheel, greyWheel.width, 320
</syntaxhighlight>
 
=={{header|Nim}}==
Line 2,815 ⟶ 2,862:
{{libheader|DOME}}
This script converts the image [https://rosettacode.org/File:Lenna100.jpg Lenna100.jpg] to grayscale and then displays the two images side by side.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color, ImageData
import "dome" for Window
 
9,476

edits