I'm a novice python programmer and I'm trying to open an image file and read it in as binary data, which I then want to convert to numpy array. I assumed by using the below code, it would read the raw bytes in as a list that is delimited somehow, which would easily translate to an array.
try:
with open(TEST_IMG, 'rb') as image_fd:
img_line = image_fd.read()
except:
print("unable to open image file")
The issue, I think, is the read() method returns the entire file as binary data but it seems to read it in as a list obj that holds the entire file as one member of a list. So when i try
img_line = np.array(img_line)
It just creates a single np array with a single element that holds all of the raw binary list. I know I could use pillow or cv2 but I really want to understand how these datatypes work in Python so I can manipulate file data no matter the origin.
Is my assumption correct about the data read in not being a list of individual bytes? And if so how would I break the list up into individual bytes so that I can convert to an np array?
Thanks