Effacer les filtres
Effacer les filtres

I have folder with name 'images' within that folder 20 sub-folders are there. that sub-folder consist 20 images with name like 'img (1).gif'. I have to read images one by one then store the hog features in the text file.

1 vue (au cours des 30 derniers jours)
objects={'apple','bat','beetle'};%apple,bat,beetle are sub-folder name
trimgs=10;
for i=1:length(objects)
for j=1:trimgs
imgpath=['.\images\' objects{i} '\img (' int2str(j) ').gif'];
I=imread(imgpath);
J = imresize(I,[256,256]);
fid=fopen('feature_vector.txt','w');
fprintf(fid,'%i\t',hog_feature_vector(J));
fprintf(fid,'\n');
fclose(fid);
end
end

Réponse acceptée

Cam Salzberger
Cam Salzberger le 29 Août 2017
What issues are you running into? Or what is your question?
I can suggest that you consider using "dir" to automatically get the "objects" name.
If you are using the same "feature_vector.txt" file for all the images, you probably want to use fopen with the 'a' option (for "append") rather than the 'w' option (for "write", discarding current contents).
  2 commentaires
bamini thavarajah
bamini thavarajah le 30 Août 2017
I'm using the same "feature_vector.txt" file for all the images. when I use fopen with 'a' that work correctly. But I want to print all image features in the matrix form. How can I modify my code?
Cam Salzberger
Cam Salzberger le 31 Août 2017
I don't know what "hog_feature_vector". However, if it is a vector of integers, then your line:
fprintf(fid,'%i\t',hog_feature_vector(J));
seems like it would work correctly. What are you seeing when you run this? I would expect it to output something similar:
x = [1 2 3 4 5];
fprintf('%i\t',x)
1 2 3 4 5
If by "matrix output" you mean you want square brackets and stuff, you can just add that before you print each line.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 29 Août 2017
  2 commentaires
bamini thavarajah
bamini thavarajah le 30 Août 2017
Modifié(e) : bamini thavarajah le 30 Août 2017
thank you.. I have to print hog features in matrix form to all images. how can I write matlab coding for this? I have used this hog function https://in.mathworks.com/matlabcentral/answers/354491-i-have-folder-with-name-images-within-that-folder-20-sub-folders-are-there-that-sub-folder-consis#comment_480718
Image Analyst
Image Analyst le 30 Août 2017
The link you gave just points back here. Basically learn how to use fprintf() and you can write out anything you want to a text file.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by