How do i split an image into 8x8 blocks using a function?

I need to split a 192x192 color image into blocks with 8x8 size. I also needed to split a grayscaled image same way which where i used this:
function x=cut(y)
for i=1:8:192
for j=1:8:192
x = y(i:i+7, j:j+7);
end
end
but i dont know how to do it with a color image.

回答 (1 件)

David Hill
David Hill 2020 年 5 月 28 日

0 投票

I assume you have the image processing toolbox. Look at Neighborhood and Block Processing.
blockproc()
col2im()

1 件のコメント

Stefan Babic
Stefan Babic 2020 年 5 月 28 日
I actually need it to be in form of a function so i would need to add the z variable to the function i used for grayscaled image. I tried:
function x=cut(y)
for i=1:8:192
for j=1:8:192
for z=1:3
x = y(i:i+7, j:j+7, 3);
end
end
end
but it gives me grayscaled image in blocks instead color image in blocks. I am not good at it so dont know whats wrong there.

サインインしてコメントする。

製品

リリース

R2020a

質問済み:

2020 年 5 月 28 日

コメント済み:

2020 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by