Ask Your Question
0

How to split image into small blocks, process on them and then join all the blocks together again?

asked 2017-09-08 06:16:55 -0500

Santhosh1 gravatar image

updated 2017-09-08 06:23:36 -0500

image description

I want to split an image into block and perform some operation on each block separately. Then join the blocks again into a single image(same shape as the original before splitting).

I am writing code in python not C++.

Any suggestions on how to do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-08 07:45:49 -0500

updated 2017-09-08 08:27:28 -0500

try to convert the code in this post or the code below

Mat src = imread("e:/getty-apple_large.jpg");

int width = src.cols;
int height = src.rows;
int GRID_SIZE = 100;

vector<Rect> mCells;

for (int y = 0; y < height - GRID_SIZE; y += GRID_SIZE) {
    for (int x = 0; x < width - GRID_SIZE; x += GRID_SIZE) {
        int k = x*y + x;
        Rect grid_rect(x, y, GRID_SIZE, GRID_SIZE);
        cout << grid_rect<< endl;
        mCells.push_back(grid_rect);
        rectangle(src, grid_rect, Scalar(0, 255, 0), 1);
        imshow("src", src);
        imshow(format("grid%d",k), src(grid_rect));
        waitKey();
    }
}
edit flag offensive delete link more

Comments

Yup I did a similar thing on python using WHILE loop ๐Ÿ‘

Santhosh1 gravatar imageSanthosh1 ( 2017-09-13 06:06:52 -0500 )edit

you can post your own answer and share your code here maybe it will be helpful for someone.

sturkmen gravatar imagesturkmen ( 2017-09-13 06:12:52 -0500 )edit

can you post your code? it will helpful for me.

HINAL03 gravatar imageHINAL03 ( 2019-02-07 03:30:42 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-08 06:16:55 -0500

Seen: 10,594 times

Last updated: Sep 08 '17