In fact, before doing "my" method of splitting the image, I was trying to create a program like that, but it is very difficult...
As the Old Rover said, the program that converts the image to the PCE colors is not enough. Besides doing that, the program must build also the map of palettes that we must import in our program. For example, something like:
const char pal_map[NUM_TILES] = { PAL0<<4, PAL0<<4, PAL1<<4, PAL2<<4 ...};
This map will say which palette will be used in each tile.
As I was saying, it was very difficult to create a program that divides the image in sections and optimizes the use of palettes automatically in every picture. For that reason I searched generic methods (splitting by rows, by columns...) and I found that splitting by squares was a decent method, because the similar colors usually are near (inside the same square), so using a different palette for a square (said for example 64x64 pixels) was the best result that I found. Of course, an optimization made automatically by a program would be awesome