Question/Issue:
I would like to be able to directly enter the pixels of an image in csv format. I need my data to be treated as an image in the edge impulse but I don’t want to update an image, but its pixels.
My data is initially a set of resistance values in a matrix of 5 rows by 10 columns, where the rows are heating profiles and the columns are cycles. It is important that the data is processed all at once, that is, the entire matrix is a single input data. I tried to enter it as a csv but I have not found a way to process the entire matrix.
Therefore, my idea was to normalize those values from 0 to 255 and generate a .png image, but it seems inefficient to have to start from some values, pass them to an image and then have the edge impulse, with the image processing block, give me the initial values of the matrix in the hexadecimal that the edge impulse uses, when I can enter those values directly.
An example of a normalized matrix in a comma separated csv would be:
0,0,1,2,2
1,27,87,165,255
1,25,78,145,225
1,24,70,129,191
0,3,7,11,14
0,3,6,10,14
0,2, 6,10,13
0,0,1,1,2
0,0,1,2,2
0,1,1,2,3
which would be in raw features of the edge impulse image processing block:
0x0, 0x0, 0x10101, 0x20202, 0x20202,
0x10101, 0x1b1b1b, 0x575757, 0xa5a5a5, 0xffffff,
0x10101, 0x191919, 0x4e4e4e, 0x919191, 0xe1e1e1,
0x10101, 0x181818, 0x464646, 0x818181, 0xbfbfbf,
0x0, 0x30303, 0x70707, 0xb0b0b, 0xe0e0e,
0x0, 0x30303, 0x60606, 0xa0a0a, 0xe0e0e,
0x0, 0x20202, 0x60606, 0xa0a0a, 0xd0d0d,
0x0, 0x0, 0x010101, 0x10101, 0x20202,
0x0, 0x0, 0x10101, 0x20202, 0x20202,
0x0, 0x10101, 0x10101, 0x20202, 0x30303
Yo can see how i can convert the normalized matrix to the hexadecimal matrix, that the edge impulse provides, in the section “Convert normalized matrix to hexadecimal that uses the processing block image”.
I would like to know if it is possible to enter the pixel values, instead of an image, and have it convert it to values, treating the data as an image.
Or if anyone knows a way to enter the data from a csv and have it all treated together, not by columns.
Project ID:
563841
Convert normalized matrix to hexadecimal that uses the processing block image
You can see in this python code how i can convert without problem from my nromalized matrix to the raw features of the processing block image.
(I put “/” before the notes in my code, because “#” indicates title in this form.
import numpy as np
from PIL import Image
/# Normalized matrix
matrix = np.array([
[0, 0, 1, 2, 2],
[1, 27, 87, 165, 255],
[1, 25, 78, 145, 225],
[1, 24, 70, 129, 191],
[0, 3, 7, 11, 14],
[0, 3, 6, 10, 14],
[0, 2, 6, 10, 13],
[0, 0, 1, 1, 2],
[0, 0, 1, 2, 2],
[0, 1, 1, 2, 3]
])
expected_values = [
0x0, 0x0, 0x10101, 0x20202, 0x20202, 0x10101, 0x1b1b1b, 0x575757, 0xa5a5a5, 0xffffff,
0x10101, 0x191919, 0x4e4e4e, 0x919191, 0xe1e1e1, 0x10101, 0x181818, 0x464646, 0x818181,
0xbfbfbf, 0x0, 0x30303, 0x70707, 0xb0b0b, 0xe0e0e, 0x0, 0x30303, 0x60606, 0xa0a0a, 0xe0e0e,
0x0, 0x20202, 0x60606, 0xa0a0a, 0xd0d0d, 0x0, 0x0, 0x10101, 0x10101, 0x20202, 0x0, 0x0,
0x10101, 0x20202, 0x20202, 0x0, 0x10101, 0x10101, 0x20202, 0x30303
]
/# Ensure values are in the range [0, 255] (they should already be)
/# Convert the matrix to hexadecimal values in 0xRRGGBB format (grayscale)
def convert_to_hex(value):
/# Convert the value to an RGB grayscale tone
value = int(value) # Ensure the value is an integer
return f’0x{value:02x}{value:02x}{value:02x}’
/# Convert the entire matrix to hexadecimal format
hex_matrix = np.vectorize(convert_to_hex)(matrix)
/# Display the matrix in hexadecimal format
print(“Matrix in hexadecimal format:”)
for row in hex_matrix:
print(', '.join(row))
/# Flatten the matrix and the list of expected values for comparison
hex_matrix_flat = hex_matrix.flatten()
expected_values_flat = [hex(v) for v in expected_values]
/# Compare the values
for i, (generated, expected) in enumerate(zip(hex_matrix_flat, expected_values_flat)):
/# Compare ignoring additional zeros (compare values without the ‘0x’ part)
if generated[2:].zfill(6) == expected[2:].zfill(6):
print(f"Index {i} - Match: {generated} == {expected}“)
else:
print(f"Index {i} - Mismatch: {generated} != {expected}”)
Result of running code:
Matrix in hexadecimal format:
0x000000, 0x000000, 0x010101, 0x020202, 0x020202
0x010101, 0x1b1b1b, 0x575757, 0xa5a5a5, 0xffffff
0x010101, 0x191919, 0x4e4e4e, 0x919191, 0xe1e1e1
0x010101, 0x181818, 0x464646, 0x818181, 0xbfbfbf
0x000000, 0x030303, 0x070707, 0x0b0b0b, 0x0e0e0e
0x000000, 0x030303, 0x060606, 0x0a0a0a, 0x0e0e0e
0x000000, 0x020202, 0x060606, 0x0a0a0a, 0x0d0d0d
0x000000, 0x000000, 0x010101, 0x010101, 0x020202
0x000000, 0x000000, 0x010101, 0x020202, 0x020202
0x000000, 0x010101, 0x010101, 0x020202, 0x030303
Index 0 - Match: 0x000000 == 0x0
Index 1 - Match: 0x000000 == 0x0
Index 2 - Match: 0x010101 == 0x10101
Index 3 - Match: 0x020202 == 0x20202
Index 4 - Match: 0x020202 == 0x20202
Index 5 - Match: 0x010101 == 0x10101
Index 6 - Match: 0x1b1b1b == 0x1b1b1b
Index 7 - Match: 0x575757 == 0x575757
Index 8 - Match: 0xa5a5a5 == 0xa5a5a5
Index 9 - Match: 0xffffff == 0xffffff
Index 10 - Match: 0x010101 == 0x10101
Index 11 - Match: 0x191919 == 0x191919
Index 12 - Match: 0x4e4e4e == 0x4e4e4e
Index 13 - Match: 0x919191 == 0x919191
Index 14 - Match: 0xe1e1e1 == 0xe1e1e1
Index 15 - Match: 0x010101 == 0x10101
Index 16 - Match: 0x181818 == 0x181818
Index 17 - Match: 0x464646 == 0x464646
Index 18 - Match: 0x818181 == 0x818181
Index 19 - Match: 0xbfbfbf == 0xbfbfbf
Index 20 - Match: 0x000000 == 0x0
Index 21 - Match: 0x030303 == 0x30303
Index 22 - Match: 0x070707 == 0x70707
Index 23 - Match: 0x0b0b0b == 0xb0b0b
Index 24 - Match: 0x0e0e0e == 0xe0e0e
Index 25 - Match: 0x000000 == 0x0
Index 26 - Match: 0x030303 == 0x30303
Index 27 - Match: 0x060606 == 0x60606
Index 28 - Match: 0x0a0a0a == 0xa0a0a
Index 29 - Match: 0x0e0e0e == 0xe0e0e
Index 30 - Match: 0x000000 == 0x0
Index 31 - Match: 0x020202 == 0x20202
Index 32 - Match: 0x060606 == 0x60606
Index 33 - Match: 0x0a0a0a == 0xa0a0a
Index 34 - Match: 0x0d0d0d == 0xd0d0d
Index 35 - Match: 0x000000 == 0x0
Index 36 - Match: 0x000000 == 0x0
Index 37 - Match: 0x010101 == 0x10101
Index 38 - Match: 0x010101 == 0x10101
Index 39 - Match: 0x020202 == 0x20202
Index 40 - Match: 0x000000 == 0x0
Index 41 - Match: 0x000000 == 0x0
Index 42 - Match: 0x010101 == 0x10101
Index 43 - Match: 0x020202 == 0x20202
Index 44 - Match: 0x020202 == 0x20202
Index 45 - Match: 0x000000 == 0x0
Index 46 - Match: 0x010101 == 0x10101
Index 47 - Match: 0x010101 == 0x10101
Index 48 - Match: 0x020202 == 0x20202
Index 49 - Match: 0x030303 == 0x30303