Hello everyone I was trying to divide an image into N different blocks in the width after I performed this code to get its edge points:
Ioriginal = imread(\'
If I understand your question correctly, you want to decompose the edge detected image into N
blocks where the height of each block is the height of the image, while the width of each block is computed such that it is of width m
, where N*m = width of image
. Therefore, each block's width is width of image / N
. Bear in mind that you must choose a value of N
such that it is evenly divisible by the width of your image. Your image has 460 columns, and so we can choose any number of blocks that is divisible by 10 for example.... so let's choose something like 10 blocks.
The easiest way to decompose your image would be to use mat2cell. This takes a 2D matrix and segments the matrix into pieces. Each piece would be stored in an individual element in a cell array. Therefore, you want to make sure that the height of each block is the same, and the width of each block is using that formula I gave you above. Therefore, you simply need to do this. I'm reading your example image that you posted directly from StackOverflow, but the image was actually uploaded as RGB. I converted it to binary directly so that we get an actual edge map:
N = 10; %// Declare total number of blocks
im = im2bw(imread('http://i.stack.imgur.com/ZvfoL.png')); %// Read in image
C = mat2cell(im, size(im,1), (size(im,2)/N)*ones(N,1));
C
will contain your image blocks, where C{idx}
will get you the image block located at index idx
. If you want to make this into a 3D array, where each slice gives you the image block you want, simply use cat and concatenate in the third dimension like so:
C_matrix = cat(3, C{:});
Therefore, to access the block at idx
, simply do C_matrix(:,:,idx)
.
As a visual representation, let's display each block in a figure:
figure;
hold on;
for idx = 1 : N
subplot(1,N,idx);
imshow(C{idx}); %// Or imshow(C_matrix(:,:,idx));
end
This is what I get:
Basically, each block is placed in a separate figure within the window itself, which is why I'm using subplot
. You can see that there is a white gap in between the blocks, which properly shows you each separated block within your image.
Good luck!