이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to Convert 4D-Single to MxNXN
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear all,
I have 100 set data 4D-Single. anyone know how to convert it to MxNxN?
Letsay my 4D-Single is cropVol, want to convert to g (see the picture in workspace)

댓글 수: 21
Bjorn Gustavsson
2022년 6월 30일
Can the number of elements in your 4-D arrays be factored into NxNxM? Or do you need to discard or extend some elements of the 4-D array, or do you want to only fill some part of the NxNxM array?
mohd akmal masud
2022년 6월 30일
Or you have any idea, how to read the data for 4D-Single for volds?
clc
clear all
close all
%testDataimages
DATASetDir = fullfile('C:\Users\USER\Downloads\BrainTS\preprocessedDataset');
IMAGEDir = fullfile(DATASetDir,'imagesTr');
volReader = @(x) matRead(x);
volds = imageDatastore(IMAGEDir, ...
'FileExtensions','.mat','ReadFcn',volReader); %THIS ONE IS DATA FOR MXNXN
% labelReader = @(x) matread(x);
matFileDir = fullfile('C:\Users\USER\Downloads\BrainTS\preprocessedDataset\labelsTr');
classNames = ["background", "tumor"];
pixelLabelID = [0 1];
% pxds = (LabelDirr,classNames,pixelLabelID, ...
% 'FileExtensions','.mat','ReadFcn',labelReader);
pxds = pixelLabelDatastore(matFileDir,classNames,pixelLabelID, ...
'FileExtensions','.mat','ReadFcn',@matRead);
Bjorn Gustavsson
2022년 6월 30일
@mohd akmal masud: You will have to explain what size your 4-D array has, what size you want to make the 3-D version, and what elements should be included (or excluded). Otherwise someone might just suggest that you take the first 12 data-points and put it into a 2x2x3 array:
NbyNbyM = reshape(cropVol(1:12),[2 2 3]);
Rik
2022년 6월 30일
Let's make this a little more understandable. Let's say you have a 2D single and want to convert this to a 1D double. How would you do that?
And what is the end purpose of this conversion?
mohd akmal masud
2022년 6월 30일
ok, lets me explain.
actually, I have 400 data set brain tumor. all the data set have the various x,y,z size.
Means all the data set have different x,y,z size.
all my data set is 4D-Single.
Because its all 4D-Single, then I cannot view in volume segmenter apps or volume viewer apps.
then need to convert all data set to x y z single.
are you all get my points?
mohd akmal masud
2022년 6월 30일
편집: mohd akmal masud
2022년 6월 30일
@Bjorn Gustavsson this one is corect.
But how to loop for 400 data set, then I want o reshap it into the origional size for all?
Rik
2022년 6월 30일
x-y-z is only 3 dimensions. Where are you getting the fourth? Is it maybe the case that your dimensions are x-y-color_channel-z (like the example below)?
load mri
size(D)
ans = 1×4
128 128 1 27
If so, permuting the color channel to the 4th position should solve the problem.
new_D=permute(D,[1 2 4 3]);
size(new_D)
ans = 1×3
128 128 27
mohd akmal masud
2022년 6월 30일
ok let me explain again.
let say one of my data is LiverTS001.mat
then I drag it into command window
>>load('LiverTS001.mat')
so the workspace will be

then I used squeeze to convert it to MxNxN
>>File = squeeze(cropVol);
then the worjspace will be

SHOULD BE the value File is something like 256x256x89 (the size data itself)
Rik
2022년 6월 30일
The squeeze function will only remove dimensions of length 1. It does not promise to make your array 3D. Apparently, none of the dimensions of cropVol have a unit length. You can use the size function to show you the actual size.
Bjorn Gustavsson
2022년 6월 30일
@mohd akmal masud: Give us this information we have been pleading for multiple times:
>> size(cropVol)
Then tell us what the different dimensions correspond to (first dimension might be the variation in x-position for example, but until you've told us that would be pure conjecture), which components you want to display which you want to discard etc. That the array is 4-D tells us very little about what anyting of it means. Is one of the dimensions time? Or wavelength of the X-rays if this is the output from an X-ray tomographic imaging system.
Rik
2022년 7월 1일
Do any of those numbers mean something to you? Do you expect 4 of something? Is your detector 176 by 224?
Without knowing what your dimensions actually mean it is not possible to help you reduce the dimension count to 3.
To explore, you could use the volume viewer on cropVol(:,:,:,k) (putting each of the 4 in a subplot). I don't know if that will help at all, since you're being very sparse with explanations.
Bjorn Gustavsson
2022년 7월 1일
When the 4-D array-size is [176 224 152 4] the only way to put your 4-D array into an N-by-N-by-M array, as you requested is to put the elements into an 128-by-128-by-1463 array. You can do that by something like:
A3D = reshape(cropVol,[128 128 1463]);
If you want or need to re-arrange the for dimensions (of still unknown meaning to us since you still will not tell us what they signify.) you can do that with the permute function. This is the only way to put all elements of an array with dimensions [176 224 152 4] into an N-by-N-by-M array, since the total number of elements factor into: 2^14 * 7 * 11 * 19.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)