I've imported an image as RGB using scipy and imread(). Say I want to separate out the "R" component and copy it to a new object in memory. The code below works:
import scipy as sp
import scipy.misc as misc
import matplotlib.pyplot as plt
%matplotlib inline
pic = misc.imread("ARBITRARY IMAGE.png");
r = pic[:,:,0].copy()
r[0,0] = 0
print(r[0,0])
print(pic[0,0,0])
Outputs the expected:
0
255
However I got there by the following path, and I don't know why they don't work:
r = pic[:,:,0]
r[0,0] = 0
print(r[0,0])
print(pic[0,0,0])
outputs:
0
0
Fair enough, I took the syntax cue from here and it involves using a slice like b = a[:]
instead of a single layer. How about:
r = pic[:]
r[0,0,0] = 0
print(r[0,0,0])
print(pic[0,0,0])
or to add an extra step:
r = pic[:]
r= r[:,:,0]
r[0,0] = 0
print(r[0,0])
print(pic[0,0,0])
Still outputs:
0
0
It is an array not a list, but this answer for arrays implies that this syntax should be okay. Basically, how come a new object isn't created in memory when I use the slice notation in my examples? I assume I am missing something else, and my googling just seems to tell me the syntax should work. Thanks for any help!