Image to patches for local features extraction

Hi All,
I have an image and I need to extract local features,so I divided it to 32 * 32 patches and size of each patch =16 *16 pixels and extract that three color histograms features locally from each patch, now I need to :
1-Store these features in the descriptor x like in figure:
2-Store these feature discroptors in the X like in figure:
3-Store these X's in the global matrix called G like in figure:
I tried this code :
patches_counter=1;
for g=1:32
for u=1:32
if nom_ones>area_of_patch_by_two
patch_h=h_seg_image_cell{g,u} ;
patch_s=s_seg_image_cell{g,u} ;
patch_v=v_seg_image_cell{g,u} ;
% Describe each patch by 3 color histograms features
[patch_h_ftr1,xh]=imhist(patch_h);
[patch_s_ftr2,xs]=imhist(patch_s);
[patch_v_ftr3,xv]=imhist(patch_v);
end
% Create features vector
x=[patch_h_ftr1;patch_s_ftr2;patch_v_ftr3];
X(:,patches_counter) = x(patches_counter);
patches_counter=patches_counter+1;
end
end
But I got this ERROR
In an assignment A(I) = B, the number of elements
in B and I must be the same.
Error in my_im2blocks1 (line 72)
X_image_vector(patches_counter) =
x_featurs_vector_patch;
Hint : Don't care about this condition
if nom_ones>area_of_patch_by_two
It works well.
Please make any correction and thanks in advance.

Réponses (2)

Capital X is undefined in the code you gave and it may not like you to poof it into existence like that. Also, before that line do
whos X
whos x
whos patches_counter
and make sure that the number of rows in X matches the length of patches_counter.

6 commentaires

hamed abdulaziz
hamed abdulaziz le 28 Fév 2014
Modifié(e) : hamed abdulaziz le 28 Fév 2014
Thank you for your fast response, I changed Capital X is to X_image_vector and I defined it at the beginning as :
X_image_vector = zeros(768,1024);
And elso changed x to
x_featurs_vector_patch
Please notice that the number of rows in X_image_vector matches the length of patches_counter where 32 * 32 =1024.
Thank you and I am waiting your answer
Image Analyst:I am waiting your answer
Image Analyst
Image Analyst le 28 Fév 2014
As far as I can tell from your code, patches_counter = 1 while the number of rows of X_image_vector is 768. And x_featurs_vector_patch doesn't even show up in your code, which means I can't see it or debug it, so it appears the bet is for you to use the debugger and figure out what sizes don't match up. Can you do that?
At the beginning I also changed x to
x_featurs_vector_patch to become :
X_image_vector (patches_counter) = x_featurs_vector_patch;
and the initial value of patches_counter = 1 then it will be increased in this line :
patches_counter=patches_counter+1;
please could you correct it now,thanks.
You never followed my suggestion of doing "whos" and you didn't attach your m-file. It's difficult for me to try to figure this out without being able to run it, because you have variables that are just suddenly there (like h_seg_image_cell{g,u}, etc.), and variables change names, etc. So I think the best bet is for you to step through this in the debugger. Don't you agree?
hamed abdulaziz
hamed abdulaziz le 1 Mar 2014
Modifié(e) : hamed abdulaziz le 1 Mar 2014
O.K I agree I will attach my m-file now,to take look on it please wait....

Connectez-vous pour commenter.

hamed abdulaziz
hamed abdulaziz le 1 Mar 2014

0 votes

I attached my_tried_code.m ,Otsu code for segmentation,and image for test; please could you run it and correct it with my thanks. Hint: I am tried to implement the steps in the thesis (page 44 to 49 in pdf-file)on this website for local features :

2 commentaires

Image Analyst:I am waiting your answer
could I have an answer?thanks

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by