Saving images into various folders

I am working on image clustering. My algorithm reads the image set from my system into MATLAB and segregates them into different clusters based on my criteria. At the end of the algorithm I have different cluster numbers with their image index content. So if I have cluster 1 with images 1,2,3,5 for example:- Cluster{1} would return a matrix.
Cluster{1} 1 2 3 5
I was wondering if I could use some function which saves those image according to the clusters in my local machine. For example, if I have image (1,2,3,5) in cluster 1 and image (4,7) in cluster 2 then I should have two folders in my working directory named Cluster1 with image 1 2 3 5 and Cluster 2 with image 4 7. I am right now trying to include for() loop by looking at each content of each cluster{}. I tried just reading and writing the same image and it took a couple of seconds which led me to believe the loop will even slower it down. Could someone please tell me the Matrix way to do it which would be faster than this.
Please let me know if this could be achieved. Thank you in advance.

Risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 19 Lug 2019
Modificato: KALYAN ACHARJYA il 19 Lug 2019
Original Question
"I am working on image clustering. My algorithm reads the image set from my system into MATLAB and segregates them into different clusters based on my criteria. At the end of the algorithm I have different cluster numbers with their image index content. I was wondering if I could use some function which saves those image according to the clusters in my local machine. For example, if I have image (1,2,3,5) in cluster 1 and image (4,7) in cluster 2 then I should have two folders in my working directory named Cluster1 with image 1 2 3 5 and Cluster 2 with image 4 7.
Please let me know if this could be achieved. Thank you in advance"
You can do this way also
Images=input images path
outDirectory1='C:\complete_path\cluster1\';
outDirectory2='C:\complete_path\cluster2\';
for i=1:.... % Image read iterration
%% Save Images
if segmented_image condition for_cluster 1 or cluster 2
%or Check from i
if cluster1
imwrite(segmented_image,strcat(outDirectory1,Images(i).name));
else %(This for cluster2)
imwrite(segmented_image,strcat(outDirectory2,Images(i).name));
end
Please Note: May be there is more easier way.

7 Commenti

My cluster is something I get from the function. Let me edit the question so that I could include every information.
What are you doing with enhanced image 1?
Edited Answer @Abhishak, it was my result image
But I have mentioned in my question that for example. I don't only have just 2 clusters. I have many. And the loop actually will slow it down.
KALYAN ACHARJYA
KALYAN ACHARJYA il 19 Lug 2019
Modificato: KALYAN ACHARJYA il 19 Lug 2019
Here loop used to call the input images one by one, I think it is required.
@Abhishake please wait for experts answers/comments.
May be: Save the cluster images in different cell array
Later call individual cell element to write the image to specific folfder.
I can understand that, but don't you think referring images directly by calling my cluster{} function and then it saves them to the system since all are present in workspace would be faster?

Accedi per commentare.

Richiesto:

il 19 Lug 2019

Commentato:

il 19 Lug 2019

Community Treasure Hunt

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

Start Hunting!

Translated by