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

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 10월 17일

0 개 추천

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

M
M 2023년 10월 17일
편집: M 2023년 10월 17일
@Dyuman Joshi, Nope, I want to reshape each image 120*160 to a vector
The output will be 19200*888
By doing that I will not loss any information right?
M
M 2023년 10월 17일
Dyuman Joshi
Dyuman Joshi 2023년 10월 17일
편집: Dyuman Joshi 2023년 10월 17일
"By doing that I will not loss any information right? "
No
"The output will be 19200*888"
In that case, use reshape
%Random input
in = rand(120,160,1,888);
s = size(in)
s = 1×4
120 160 1 888
out = reshape(in,s(1)*s(2)*s(3),s(4));
size(out)
ans = 1×2
19200 888
M
M 2023년 10월 17일
@Dyuman Joshi these numbers are not fixed, I want something general
Dyuman Joshi
Dyuman Joshi 2023년 10월 17일
@M, I have edited my response, please check above.
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

M
M
2023년 10월 17일

댓글:

2023년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by