How can I save images in a matrix?
조회 수: 13 (최근 30일)
이전 댓글 표시
Hello my friends . I get my images with this code, but what if I don't want to save all the images in the output? (last two lines)
That is, it should be stored in a matrix and finally saved in CSV or TXT format. In this way, I want any image that was needed to be displayed for me later.
clc
clear
close all
cd training_data_out\
folderInfo = dir('**/*.wav');
cd ..\
addpath training_data_out\
% working (current) folder
for i=1:length(folderInfo)
filename = folderInfo(i).name
[x,Fs] = audioread(filename);
x=decimate(x,4);
% % st transform
[st_out,t,f]=st(x,25,350,1,1);
zz=abs(st_out);
im = ind2rgb(im2uint8(rescale(zz)), colormap);
filename_out = [filename(1:length(filename)-4) '.png']
imwrite(imresize(im, [224 224]), filename_out);
댓글 수: 0
채택된 답변
Walter Roberson
2023년 5월 23일
Replace
imwrite(imresize(im, [224 224]), filename_out);
with
filenames{i} = filename_out;
saved_im{i} = imresize(im, [224 224]);
Then later you can
imshow(saved_im{i})
to view an image without having yet saved it to file.
When you finally decide to save it to csv of text file, you have a bit of a challenge. You used ind2rgb so we know that for sure the data for each file is RGB, which means it is stored as a 3D array. csv files are really only designed for 2D data, so it is not clear how you would like the 3D data stored in the csv file.
댓글 수: 0
추가 답변 (1개)
Luca Ferro
2023년 5월 23일
편집: Luca Ferro
2023년 5월 23일
you can store them in a cell array by doing:
imgArray{1,1}=imread('whateverimage.png');
imgArray{1,2}=imread('whateverimage2.jpeg');
...
imgArray{1,n}=imread('whateverimageN.jpeg');
and so on. Obiously you can allocate them using the loop you already have.
Then to access them use curly brackets.
imgArray{1,1}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!