Suppose there is a black and white image of 10x10 pixels in size, then it needs to be converted to a 10x10 matrix in which the black color will correspond to 1, and 0 to white or you can use 1 and -1 it does not really matter (one of these). Preferably in C ++.
unsigned char* readBMP(const char* filename) { int i; FILE* f = fopen(filename, "rb"); unsigned char info[54]; fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header // extract image height and width from header int width = *(int*)&info[18]; int height = *(int*)&info[22]; int size = 3 * width * height; unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once fclose(f); for (i = 0; i < size; i += 3) { unsigned char tmp = data[i]; data[i] = data[i + 2]; data[i + 2] = tmp; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { cout << "R: " << (int)data[3 * (i * width + j)] << "; G: " << (int)data[3 * (i * width + j) + 1] << "; B: " << (int)data[3 * (i * width + j) + 2] << endl; } } return data; }