MATLAB: How to divide an RGB image using blockproc function

digital image processingimage segmentation

i want to resize an RGB image from 512X512 to 256X256 + i want to divide it into 4 equal blocks and take each block and change it from RGB to HSV, all of this using blockproc function or if you can tell me another effective way, here is my code in matlab:
f= imread ('lena_rgb.tiff');
h= rgb2hsv(f);
fun = @(block_struct) imresize(block_struct.data,h);
I2 = blockproc(f,[2 2],fun);
figure(1),imshow(f);
figure(2),imshow(I2);
i had all these errors:
??? Function BLOCKPROC encountered an error while evaluating the user supplied function handle,
FUN.
The cause of the error was:
Error using ==> imresize>scaleOrSize at 393
Invalid scale or size input argument.
Error in ==> imresize>parsePreMethodArgs at 364
[scale, output_size] = scaleOrSize(next, next_arg);
Error in ==> imresize>parseInputs at 257
[params.A, params.map, params.scale, params.output_size] = ...
Error in ==> imresize at 141
params = parseInputs(varargin{:});
Error in ==> @(block_struct)imresize(block_struct.data,h)
Error in ==> blockprocFunDispatcher at 14
output_block = fun(block_struct);
Error in ==> blockprocInMemory at 71
[ul_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...
Error in ==> blockproc at 248
result_image = blockprocInMemory(a,block_size,fun,border_size,...
Error in ==> ff4 at 12
I2 = blockproc(f,[2 2],fun);

Best Answer

Why not just do something simple like
rgbSmall = imresize(rgbBig, 0.5);
hsv = rgb2hsv(rgbSmall);
As far as the 4 equal blocks - I have no idea what you're talking about. The whole image gets converted to hsv - every single pixel. So since every single pixel gets converted into hsv, of course each block (quadrant) will also get converted. There is nothing extra that you need to do.