How to resolve the algorithm Grayscale image step by step in the Octave programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Grayscale image step by step in the Octave 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 Octave programming language

Source code in the octave programming language

function [grayImage] = colortograyscale(inputImage)
   grayImage = rgb2gray(inputImage);


function gray = rgb2gray (rgb)
    switch(class(rgb))
    case "double"
      gray = luminance(rgb);
    case "uint8"
      gray = uint8(luminance(rgb));
    case "uint16"
      gray = uint16(luminance(rgb));
    endswitch
endfunction

function lum = luminance(rgb)
   lum = 0.2126*rgb(:,:,1) + 0.7152*rgb(:,:,2) + 0.0722*rgb(:,:,3); 
endfunction


  

You may also check:How to resolve the algorithm String length step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Scala programming language
You may also check:How to resolve the algorithm Character codes step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm S-expressions step by step in the Ada programming language
You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the Arturo programming language