This file is indexed.

/usr/share/octave/packages/image-2.2.2/rgb2gray.m is in octave-image 2.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
## Copyright (C) 2000, 2001 Kai Habel <kai.habel@gmx.de>
## Copyright (C) 2012 Carnë Draug <carandraug+dev@gmail.com>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} @var{gray}= rgb2gray (@var{rgb})
## Convert RGB image or colormap to grayscale.
##
## If @var{rgb} is an RGB image, the conversion to grayscale is weighted based
## on the luminance values (see @code{rgb2ntsc}).  Supported classes are single,
## double,  uint8 and uint16.
##
## If @var{rgb} is a colormap it is converted into the YIQ space of ntsc.  The
## luminance value (Y) is taken to create a gray colormap.
##
## @seealso{mat2gray, ntsc2rgb, rgb2ind, rgb2ntsc, rgb2ycbcr}
## @end deftypefn

function gray = rgb2gray (rgb)

  if (nargin != 1)
    print_usage();
  endif

  if (iscolormap (rgb))
    gray = rgb2ntsc (rgb) (:, 1) * ones (1, 3);

  elseif (isimage (rgb) && ndims (rgb) == 3)
    warning ("off", "Octave:broadcast", "local");

    ## mutiply each color by the luminance factor (this is also matlab compatible)
    ##      0.29894 * red + 0.58704 * green + 0.11402 * blue
    gray = im2double (rgb) .* permute ([0.29894, 0.58704, 0.11402], [1, 3, 2]);
    gray = sum (gray, 3);

    switch (class (rgb))
    case {"single", "double"}
      ## do nothing. All is good
    case "uint8"
      gray = im2uint8 (gray);
    case "uint16"
      gray = im2uint16 (gray);
    otherwise
      error ("rgb2gray: unsupported class %s", class(rgb));
    endswitch

  else
    error ("rgb2gray: the input must either be an RGB image or a colormap");
  endif
endfunction

# simplest test, double image, each channel on its own and then all maxed
%!shared img
%! img = zeros (2, 2, 3);
%! img(:,:,1) = [1 0; 0 1];
%! img(:,:,2) = [0 1; 0 1];
%! img(:,:,3) = [0 0; 1 1];
%! img = rgb2gray (img);
%!assert ([img(1,1) img(1,2) img(2,1) img(2,2)], [0.29894 0.58704 0.11402 1]);