how do i divide an image into blocks?

I have this image (2848 x 4288) and i want to divide it into 9 blocks and perform some operations on individual or each block. For example i perform this operations on an image:;
y = rgb2gray(imresize(imread('DSC_0009.jpg'),.2));
z = 255.0 - 1.0 * double(y);
z = z ./5 ;
z2 = imfilter(z, fspecial('average', 15));
z2(z2 > 35) = 35;
z2(z2 < 30) = 0;
surface(z2);
shading interp;
axis ij;
axis tight;
I want to do a similar operation on each of the blocks and output it as well.
thank you.

답변 (2개)

Image Analyst
Image Analyst 2015년 8월 16일

0 개 추천

See the FAQ for code to perform it two different ways, normal indexing, and the cell2mat() function: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
Image Analyst
Image Analyst 2015년 8월 16일

0 개 추천

You can also use blockproc() if you don't need to store the subimages but just need to perform some operation on them and give you an output image. See attached demos for a variety of ways to use blockproc().

댓글 수: 5

Rey Kelvin Peralta
Rey Kelvin Peralta 2015년 8월 16일
편집: Walter Roberson 2015년 8월 16일
How do i perform operations on individual blocks? I have this code:
function test_block
% Function that is used to process each block
function z2 = process_block(x)
y = x.data; % Get the block itself
% Apply the operations
z = 255.0 - 1.0 * double(y);
z = z ./5 ;
z2 = imfilter(z, fspecial('average', 15));
z2(z2 > 35) = 35;
z2(z2 < 30) = 0;
end
% Specify total number of blocks per row and column
num_blocks_row = 3;
num_blocks_col = 3;
% Read in image
img = rgb2gray(imread('DSC_0009.jpg'));
% Determine how large each block should be
block_size = floor([size(img,1)/num_blocks_row size(img,2)/num_blocks_col]);
% Perform processing of each block
out = blockproc(img, block_size, @process_block);
% Show the results
surface(out);
shading interp; axis ij; axis tight;
end
but this cant access individual blocks and perform filtering and thresholding with different values/threshold values.
Thank you.
Image Analyst
Image Analyst 2015년 8월 16일
Follow the example of blockproc_demo2 where I use myFilter. You can put whatever code you want into that function, such as the code you showed above.
Rey Kelvin Peralta
Rey Kelvin Peralta 2015년 8월 18일
Also sir, is there a way we can export my code or the figure/surface/3dsurface of this code in to a format into which blender can read it? please help
Image Analyst
Image Analyst 2015년 8월 19일
I don't know. I've never used blender. However using fwrite() or fprintf() you can create any file you want.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2015년 8월 16일

댓글:

2017년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by