dividing RGB image into overlaping blocks

I have a RGB image,please can anyone tell how to divide the image into OVERLAPPING BLOCKS OF SIZE 64 64.then i want to perform some operation on each block
Kindly assist

1 Comment

What overlaps? Does each block overlap other blocks, or do the blocks just overlap the original image with no block-to-block overlap (in essence the blocks perfectly tile the image like you were laying tiles on a floor)?

Sign in to comment.

 Accepted Answer

Change your
@(block_struct)kmeans(block_struct.data,4)
to
@(block_struct)kmeans(double(block_struct.data),4)

More Answers (1)

blockproc() with BorderSize option, and with TrimBorder 0

9 Comments

Please follow this code
fun=@(block_struct) block_struct.data;
rgbBlock=BLOCKPROC(rgbimage,[64 64],fun,'BorderSize',[3 3],'TrimBorder',false);%Image Segmentation
i have this code
fun = @FunctionaName;
frame=imread('peppers.png')
% block processing on the image
a = blockproc(frame,[8 8],fun,'BorderSize',[4 4]);
a=blkproc(frame,[8 8],[4 4] ,fun);
but i get error fun = @FunctionaName;
please assist
blockproc, not blkproc !
fun = @FunctionaName; should be changed so that FunctionName is the name of the function you want to be called on each block.
ok i did as per
fun=@(block_struct) imresize(block_struct.data,0.5);
frame=imread('peppers.png')
% block processing on the image
a = blockproc(frame,[64 64],fun,'BorderSize',[4 4]);
imshow(a)
i get anwer ,but if apply k means as
fun=@(block_struct) kmeans(block_struct.data,4);
i get error
Set TrimBorder to false like Algorithms Analyst showed.
Saying "I get error" is not very informative.
i get long error
??? Function BLOCKPROC encountered an error while evaluating the user supplied function handle, FUN.
The cause of the error was:
Error using ==> plus Class of operand is not supported.
Error in ==> kmeans>distfun at 722 D(:,i) = D(:,i) + (X(:,j) - C(i,j)).^2;
Error in ==> kmeans at 329 D = distfun(X, C, distance, 0);
Error in ==> @(block_struct)kmeans(block_struct.data,4)
Error in ==> blockproc>userfunDispatcher at 788 output_block = fun(input_struct);
Error in ==> blockproc at 249 [output_block has_output] = userfunDispatcher(fun,input_struct,trim_border,false);
Error in ==> Untitledk at 8 rgbBlock=BLOCKPROC(rgbimage,[64 64],fun,'BorderSize',[3 3],'TrimBorder',false)
why you applying clustering algorithm on each block?can you please clear this point?actually what are you trying to do?please clearify your target.....as you told that you want to divid image by 64x64 and overlapped and now you appplied kmeans...clear it
See how they use kmeans here kmeans demo and how they have to reshape the output of kmeans.
for each block i have to find k means ans then have t perform some other operations also,finally have o set a colour for each block depepnding upon other previous values

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!