anyone know how to open .dmi file
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear all,
I have .dmi file (as attached). Then I try coding as below:
unzip alders.zip
fid = fopen('alders.dmi','rb');
arr = fread(fid,'int8');
fclose(fid);
dim = [64,64,128];
arr = reshape(arr,dim)
But I got error
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Anyone can help me?
0 Kommentare
Antworten (3)
Shubham
am 8 Okt. 2024
Bearbeitet: Shubham
am 8 Okt. 2024
It appears that the error is due to a mismatch between the number of elements in your array and the dimensions you’re trying to reshape it into. The reshape function requires that the total number of elements remains the same before and after reshaping.
unzip alders.zip
fid = fopen('alders.dmi','rb');
arr = fread(fid,'int8');
% Actual Size of the array
disp(size(arr));
% Number of elements in reshaped array
disp(64*64*128);
% Notice that the number of elements are not same
fclose(fid);
dim = [64,64,128];
% The number of elements should be same for both cases
% Removing the first element of the array.
arr = arr(2:length(arr));
arr = reshape(arr,dim); %No errors now
In order to resolve the error you are facing, either make changes to the dimensions for the reshaped array, or truncate one element to keep the same dimensions. This is to ensure that the number of elements should remain constant after reshaping the array.
I hope this resolves the issue!
0 Kommentare
Les Beckham
am 8 Okt. 2024
There are two issues. One is that your fread command is converting the int8 data to doubles when reading. The other is that the number of bytes in the .dmi file is not equal to 64 * 64 * 128.
unzip alders.zip
fid = fopen('alders.dmi','rb');
arr = fread(fid,'*int8'); %<<< add the * to tell Matlab not to convert the numbers to doubles
fclose(fid);
dim = [64,64,128];
size(arr,1)
prod(dim)
size(arr,1) == prod(dim)
% arr = reshape(arr,dim)
0 Kommentare
Sameer
am 8 Okt. 2024
Bearbeitet: Sameer
am 8 Okt. 2024
The error occured because the total number of elements is not equal to 64 * 64 * 128.
You can verify and adjust as follows:
numElements = numel(arr);
dim1 = 64;
dim2 = 64;
% Calculate the third dimension
dim3 = numElements / (dim1 * dim2);
% Check if dim3 is an integer
if mod(dim3, 1) ~= 0
error('The dimensions do not match the number of elements.');
end
% Reshape the array
arr = reshape(arr, [dim1, dim2, dim3]);
disp(['Reshaped array size: ', num2str(size(arr))]);
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration 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!