MATLAB: How to make this code a generic code for any size of the image? I am reading an image of size 256 by 256. I am doing this task 4 times . I want to make it generic using a for loop. so that i can make it for a block size even smaller

split image into blocks

clc
clear
s=double(imread('cameraman.tif'))/256;
[M,P]=size(s)
N=128;
size(s)
blk=s(1:1+N-1, 128:128+N-1);
[B,Mu,Ml]=myBTCencoder(blk,N);
figure
imshow(B)
blk=s(1:1+N-1, 1:1+N-1);
[B,Mu,Ml]=myBTCencoder(blk,N);
figure
imshow(B)
blk=s(128:128+N-1, 128:128+N-1);
[B,Mu,Ml]=myBTCencoder(blk,N);
figure
imshow(B)
blk=s(128:128+N-1, 1:1+N-1);
[B,Mu,Ml]=myBTCencoder(blk,N);
figure
imshow(B)

Best Answer

  • The FAQ on how to split an image up into non-overlapping blocks might help: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F