How to divide an image into blocks in MATLAB?

后端 未结 4 615
野的像风
野的像风 2020-11-27 20:23

I have a 256x256 image and I want to divide it into 4 blocks of 128x128 each and address them as A1 to A4. Now I want to call them separately and do some operations on them.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 21:00

    Its it better for you to make your program work for all sizes of images not just for 256*256.

    
    [row, col]=size(your_image);
    mr = round(row/2); % median of rows
    mc = round(col/2); % median of columns
    % Now divide your image and call each of them separately and do what ever you   want
    top_left  = your_image(1:mr  , 1:mc);
    top_right = your_image(1:mr  , (mc+1):col); 
    bot_left  = your_image((mr+1):row , 1:mc);
    bot_right = your_image((mr+1):row , (mc+1):col);
    % final stage is to combining these parts again to return to its original shape 
    Back_to_original = [top_left,top_right ; bot_left,bot_right]; `   
    
    

    hope this will be useful for you.

提交回复
热议问题