Borrar filtros
Borrar filtros

How to save patches of all images in a single .mat file?

1 visualización (últimos 30 días)
hirra awan
hirra awan el 15 de Jul. de 2020
Comentada: hirra awan el 18 de Jul. de 2020
i have a code that divides image into patches of size 32*32 and also divide the corresponding labeled image into same size of patches. i want to save and concatenate all the patches of all the images in a .mat file, but my code is saving only the patches of last image. please can someone help me with this problem?
a = dir('C:\Users\admin\Desktop\img\*.png');
b = dir('C:\Users\admin\Desktop\lbl\*.png');
for i = 1:length(a)
filename=strcat('C:\Users\admin\Desktop\img\',a(i).name);
image=imread(filename);
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
Y = 0.299 * R + 0.587 * G + 0.114 * B;
U = -0.14713 * R - 0.28886 * G + 0.436 * B;
V = 0.615 * R - 0.51499 * G - 0.10001 * B;
image = cat(3,Y,U,V);
[image_patches] = hellopatches(image, 32, 20);
filenamel=strcat('C:\Users\admin\Desktop\lbl\',b(i).name);
label=imread(filenamel);
[labels] = hellopatches_label(label, 32, 20);
data = cat(1, image_patches,labels);
end
data = data';
data = shuffleRow(data);
save data.mat;

Respuestas (2)

neuroDuck
neuroDuck el 15 de Jul. de 2020
Editada: neuroDuck el 15 de Jul. de 2020
Hi Hirra,
You are overwriting 'data' every time the loop runs. Simply index it - e.g. data(i) - or add it to a cat() to make every image accessible outside of the loop.
Kind regards.
  10 comentarios
Walter Roberson
Walter Roberson el 18 de Jul. de 2020
At present, you create a 3073 x 5625 array for the first image, and a 3073 x 5184 array for the second image.
We know from the above discussion that you do not want to put those two arrays as seperate entries in a cell array.
How would you like to store the 3073 x 5625 array together with the 3073 x 5184 arrary ? Would you want the result to be a 3073 x 10809 array?
I cannot seem to find your source code for hellopatches in the discussion, so I have attached it. It appears to me that since your images are not all the same size, that we should not be necessarily be expecting that the output of hellopatches will always have 3073 rows or 5625 columns.
hirra awan
hirra awan el 18 de Jul. de 2020
Yes exactly I want to store 3073*5625 with 3073*5184 array. This is the data of just 2 images. i have almost 160 images in total. I want the final .mat file to store data like this 3073*10809 .
I attached the hello patches code please check.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 15 de Jul. de 2020
data = cat(1, image_patches,labels);
That code is overwriting all of data each iteration.
It looks to me as if data will not be a vector, but I do not seem to be able to locate any hellopatches() function so I cannot tell what shape it will be. As you are not doing imresize() I also cannot be sure that all of the images are the same size, so I cannot be sure that data will be the same size for each iteration. Under the circumstances you should be considering saving into a cell array.
Note: please do not post the same query multiple times. I found at least 9 copies of your query :(
  10 comentarios
Walter Roberson
Walter Roberson el 17 de Jul. de 2020
// is not a permitted comment marker in MATLAB.
hirra awan
hirra awan el 18 de Jul. de 2020
i know.. // these are not in the code, i put them here to elaborate my code and problem.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by