I am new to Python and am trying to extract RGB-encoded pixel labels from a numpy array. For example:
image.shape
>> (256, 256, 3)
to be converted to:
image.shape
>> (256, 256, 1)
based on a custom function. In Javascript such a function would be (the exact RGB encoding is, of course, irrelevant - but being able to use a custom function is relevant):
RGBtoVal = ([r,g,b])=>{
r = Math.floor(r*9/255);
g = Math.floor(g*9/255);
b = Math.floor(b*9/255);
if (r>0) return r+18;
if (g>0) return r+9;
return b;
}
I understand that reshape and squeeze are helpful in reducing the dimensionality but without a function. Also, is a numpy matrix of shape (256,256,1) the same as (256,256)?