ok i want to resize the whole RGB image and divide it into 4 blocks using block proc then convert each block to HSV
how to divide an RGB image using blockproc function
1 次查看(过去 30 天)
显示 更早的评论
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);
采纳的回答
Image Analyst
2011-10-23
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.
9 个评论
Image Analyst
2011-10-29
Find the max value in each array, then divide the pixel value by the max, multiply by the number of levels, and take the ceil. See demo below:
% Generate sample data.
S = magic(6);
% Specify the number of quantization levels.
numberOfLevels = 3;
% Find the max.
maxValue = max(S(:));
% Put all pixels into one of the "numberOfLevels" levels.
for row = 1:size(S, 1)
for col = 1 : size(S, 2)
quantizedValue(row, col) = ceil(numberOfLevels * S(row, col)/maxValue);
end
end
% Display it
quantizedValue
更多回答(4 个)
Walter Roberson
2011-10-22
The second argument to imresize() should be the scale factor that you want to use, such as 0.5
0 个评论
Image Analyst
2011-12-10
yasmine: I'm still not sure what you want to do. Sure, I can give you a blockproc demo, if that's what you want. I really don't see why it would be necessary in order to (1) convert your image to hsv, (2) quantize your image into a discrete number of levels, or (3) quantize your histograms into a certain number of bins. I don't even know why you said you want to do those things. You haven't given us the context or "big picture" or what you're trying to do at all, so I can only guess if what you're asking to do is even necessary (my guess is that they're not). Moreover, why pick so few bins: 8(H) x 3(S) x 3(V) bins? I'd make each dimension at least 10 times that big. Why are you higtogramming them anyway? Is it to visualize the histogram so you can pick a threshold? Finally you can replace any constants by variables where you assign the variable to whatever constant you want like instead of hsvBlock1 = hsv(1:128, 1:128, :); you would have col1=1; col2 = 128; row1=1; row2=128; hsvBlock1 = hsv(row1:row2, col1:col2, :); hsvBlock1 = hsv(1:128, 1:128, :);
7 个评论
Walter Roberson
2011-12-11
Section 3.1 of that paper says,
"3.1 Data set: Wang's [15] dataset comprising of 1000 Corel images with ground truth. The image set comprises 100 images in each of 10 categories. The images are of the size 256 x 384 or 384X256. But the images with 384X256 are resized to 256X384."
Therefore your code only has to deal with images of size 256 x 384, and you should be resizing the 384x256 images to 256 x 384 before entering the part of your code that needs to divide the image up in to blocks.
The question of how to divide up parametrically is thus irrelevant, and a straight blockproc() or mat2cell() can be used.
Image Analyst
2011-12-11
yasmine: What I was hoping you'd figure out is that you can just do something like
[rows columns numberOfColorBands] = size(hsvimage);
halfRows = floor(rows/2);
thirdCols = floor(columns/3);
block1 = hsvimage(1:halfRows, 1:thirdCols , :);
block2 = hsvimage(1:halfRows, thirdCols +1:thirdCols *2, :);
block3 = hsvimage(1:halfRows, thirdCols *2+1:end, :);
block4 = hsvimage(halfRows+1:end, 1:thirdCols , :);
block5 = hsvimage(halfRows+1:end, thirdCols +1:thirdCols *2, :);
block6 = hsvimage(halfRows+1:end, thirdCols *2+1:end, :);
Now set up your histogram edges as in the paper and call histc(block1(:), histEdges), or whatever the calling protocol is, for each of the 6 blocks.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!