Filter löschen
Filter löschen

How to convert images to vectors

8 Ansichten (letzte 30 Tage)
M
M am 17 Okt. 2023
Kommentiert: Walter Roberson am 17 Okt. 2023
How can I convert my images with size 120 160 1 888 to vectors ?
where 120* 160 is the size of each gray scale image, 1 is the number of channels, 888 is the number of images
so the output will be matrix and each column in the matrix is an image, I should end up with 888 vectors each vector is image

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 17 Okt. 2023
From what I have understood -
%Random input
in = rand(120,160,1,888);
s = size(in);
%Convert the input to a cell vector
out = mat2cell(in,s(1),s(2),s(3),ones(1,s(4)));
size(out)
ans = 1×4
1 1 1 888
%Modify the size of the output
out = squeeze(out)
out = 888×1 cell array
{120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double} {120×160 double}
  6 Kommentare
Dyuman Joshi
Dyuman Joshi am 17 Okt. 2023
@M, I have edited my response, please check above.
Walter Roberson
Walter Roberson am 17 Okt. 2023
in = rand(120,160,1,888);
s = size(in);
out = cell2mat(squeeze(cellfun(@(P) P(:), num2cell(in, 2),'uniform', 0)));
whos out
Name Size Bytes Class Attributes out 19200x888 136396800 double

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by