pls help me to solve this question

i am working on a project in which i need to divide an image of size M*N into overlapping blocks of size B*B. i tried in number of ways but i am getting some error......pls help me

6 Comments

Show what the errors are then and which ways you tried. It is better than just expecting a whole answer. This kind of question always brings further questions such as what do you expect to happen if M or N isn't a neat multiple of the block size minus the overlap, what is the overlap, etc etc?
Here is my code.
grayImage = A1;
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
figure;
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', 16);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Divide the image up into 4 blocks.
% Let's assume we know the block size and that all blocks will be the same size.
blockSizeR = 128; % Rows in block.
blockSizeC = 128; % Columns in block.
% Figure out the size of each block.
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
% Preallocate a 3D image
image3d = zeros(wholeBlockRows, wholeBlockCols, 3);
% Now scan though, getting each block and putting it as a slice of a 3D array.
sliceNumber = 1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
% Let's be a little explicit here in our variables
% to make it easier to see what's going on.
row1 = row;
row2 = row1 + blockSizeR - 1;
col1 = col;
col2 = col1 + blockSizeC - 1;
% Extract out the block into a single subimage.
oneBlock = grayImage(row1:row2, col1:col2);
% Specify the location for display of the image.
subplot(2, 2, 1);
imshow(oneBlock);
% Make the caption the block number.
caption = sprintf('Block #%d of 4', 2);
title(caption, 'FontSize', 16);
drawnow;
% Assign this slice to the image we just extracted.
image3D(:, :, 3) = oneBlock;
sliceNumber = sliceNumber + 1;
end
end
pls someone help me with the above question
It looks like this came from the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F However the FAQ has NON overlapping blocks. So, which do you want: the blocks to overlap each other, or not overlap and be tiled adjacent/touching each other?
@ image analyst i want to divide an image into overlapping blocks. i dont want readymade code. can u explain me what is the exact difference between overlapping blocks and non overlapping blocks using example.
please explain your answer for this question: to divide 640*480 image into overlapping blocks of size 20*20.
@Tushar Muratkar,
It should be you who explain what you mean by divide an image into overlapping blocks (and what you intend to do with that division). We have no idea.
Note that if you want to apply a function to a sliding window over the image, you can use nlfilter

Sign in to comment.

Answers (0)

Asked:

on 28 Jul 2017

Commented:

on 1 Aug 2017

Community Treasure Hunt

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

Start Hunting!