C ++无法弄清楚如何改变图像

时间:2016-06-11 02:38:11

标签: c++ image shuffle

我现在已经坚持了一下。我需要将图像分解为9个盒子(2D阵列)并将其洗牌。我导入了两次图像,一次是src,一次是目标,所以我得到了两个数组。我需要让src图像随机播放并输出到目标中,而不重复拼贴,但我无法弄清楚如何做到这一点....这是我的代码:

#include "pgmio.h"
#include <iostream>
#include <ctime>

void shuffle_image_3(PGM src, PGM & target);

int main(int argc, char ** argv) {
    srand(time(NULL));

    PGM src, target;
    readPGM("random.pgm", src); //2D array src
    readPGM("random.pgm", target); //2D array target

    shuffle_image_3(src, target);
    writePGM("random_shuffled.pgm", target);
    system("random_shuffled.pgm");
    return 0;
}

void shuffle_image_3(PGM src, PGM & target) {
    if (src.row != target.row || src.col != target.col) {
        return;
    } //If sizes aren't equal, returns nothing

    //"used[i][j]==true means the tile in source
    //at row i and column j has been copied to target
    //initially, they are all false, meaning none of the
    //tiles in the source have been copied

    bool used[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            used[i][j] == false;
        }
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            //randomly select a tile in src
            //copy pixel values from tile to target
            int r, c;
            do {
                //randomly select tile in src
                r = rand() % 3;
                c = rand() % 3;
            } while (used[r][c] == true);

            used[r][c] == true;


          //dont know how to move the tile at row r and col c from src 
          //to target at row i and col j

        }
    }
}

0 个答案:

没有答案