divide an RGB image in to block of size 16*16
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have an rgb image frame extracted from a video of size 240x320x3 , I am trying to make in to blocks of 16x16x3. The blocks will be used for analysis between different frames.
In my example i should have an array of 15x20 blocks, in which each block will have a 16x16x3 information.
as a first trail I made like 300(15*20 = 300) blocks Matlab shows busy and it never ends with the code I made. is this the way we do ? please suggest a way I can
I had seen examples with mat2cell but how to use it in 3d image ? here is my code
videoObject = VideoReader(Filename);
Im = read(videoObject,120);
[r,c,rgb] = size(Im);
Blocks = zeros(r/16,c/16,rgb,r*c);
for rc = 1:r*c
for row = 1:(r/16)
for col = 1:(c/16)
Blocks(1:16,1:16,:,rc) = Im(((16*(row-1))+1):(16*row),((16*(col-1))+1):(16*col),:);
end
end
end
댓글 수: 0
채택된 답변
Walter Roberson
2015년 11월 9일
Use blockproc() or mat2cell
[r,c,rgb] = size(Im);
Blocks = mat2cell(Im, 16*ones(1,r/16), 16*ones(1,c/16), rgb);
Provided, of course, that the image is divisible by exactly 16 in rows and columns.
The result will be a cell array of blocks, each of which is 16 x 16
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!