How to resolve the algorithm Grayscale image step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Grayscale image step by step in the PureBasic programming language
Table of Contents
Problem Statement
Many image processing algorithms are defined for grayscale (or else monochromatic) images.
Extend the data storage type defined 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 CIE: 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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Grayscale image step by step in the PureBasic programming language
Source code in the purebasic programming language
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 = Red(color)
g = Green(color)
b = Blue(color)
gray = 0.2126*r + 0.7152*g + 0.0722*b
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()
EndProcedure
You may also check:How to resolve the algorithm Longest common subsequence step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Odd word problem step by step in the F# programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Leonardo numbers step by step in the Scala programming language
You may also check:How to resolve the algorithm Four is magic step by step in the Perl programming language