0

I am currently working on a python/opencv implementation to create a HDR Image out of images with different exposures. I found an matlab code example, which has a function, that I am not understanding.

function [ red, green, blue ] = sample( image, sampleIndices )

%Takes relevant samples of the input image

redChannel = image(:,:,1);
red = redChannel(sampleIndices);

greenChannel = image(:,:,2);
green = greenChannel(sampleIndices);

blueChannel = image(:,:,3);
blue = blueChannel(sampleIndices);

The function sample takes an image as an argument, which is declared in another class by

image = cv2.imread(dir_name + filenames[i])

Now my question is, what exactly do these assignments mean:

(matlab code)
redChannel = image(:,:,1);
red = redChannel(sampleIndices);

I do get different results for redChannel in matlab and python:

(python code)
red_channel = image[:, :, 1]

I really don't know, if my python code is exactly the same, as it's written above in matlab. And what is the syntax for writing the same in python code? Especially this line, what is happening here?:

red = redChannel(sampleIndices);

I am very thankful for every help, you could provide.

Cheers, Busofyan

1 Answers1

0

Matlab indexing starts at 1, Python starts at 0. When you use red_channel = image[:, :, 1] you are not reading the first (red) but the second channel (blue).

Joe
  • 6,758
  • 2
  • 26
  • 47
  • Nice thanks for the advice. Do you have any idea, what this line is doing: red = redChannel(sampleIndices); – Busofyan Jan 21 '18 at 15:49
  • This will pick some individual pixels out of the array. – Joe Jan 21 '18 at 15:54
  • In numpy this would be called advanced indexing (https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#advanced-indexing) – Joe Jan 21 '18 at 15:55