Conversion matlab code to python code

4 vues (au cours des 30 derniers jours)
hyounwook jung
hyounwook jung le 3 Avr 2019
Commenté : Rik le 3 Avr 2019
I want to convert matalb code to python code.
But I am having difficulty converting the code so, leave a question.
IM = load_nii(uigetfile('*.nii','Select the Analyze file format'), [], [], [], [], [], 1); % Load 3D CT Image
movingVolume = flipud(IM.img);
spineVolume = movingVolume;
[row,col,slice] = size(movingVolume);
for z=1:slice
for i=1:row
for j=1:col
if j < 330
movingVolume(i,j,z) = -1;
end
end
end
end
for z=1:slice
for i=1:row
for j=1:col
if movingVolume(i,j,z) > -800
movingVolume(i,j,z) = 1;
else
movingVolume(i,j,z) = 0;
end
end
end
end
  2 commentaires
Guillaume
Guillaume le 3 Avr 2019
It looks like you've already done the conversion and since you don't tell us anything about the original code we can't tell if it's correct or not. You also don't ask a question, so it's unclear what you want.
The code you have written can be greatly simplified:
IM = load_nii(uigetfile('*.nii','Select the Analyze file format'), [], [], [], [], [], 1); % Load 3D CT Image
movingVolume = flipud(IM.img);
spineVolume = movingVolume; %not sure what the purpose of that is. You don't show SpineVolume being used
movingvolume(:, 1:329, :) = -1; %replace your first loop
movingvolume = movingvolume > -800; %replace your 2nd loop
Rik
Rik le 3 Avr 2019
Some small edits for edge cases:
IM = load_nii(uigetfile('*.nii','Select the Analyze file format'), [], [], [], [], [], 1); % Load 3D CT Image
movingVolume = flipud(IM.img);
spineVolume = movingVolume; %not sure what the purpose of that is. You don't show SpineVolume being used
movingvolume(:, 1:min(329,end), :) = -1; %replace your first loop
movingvolume = double(movingvolume > -800); %replace your 2nd loop
%or possibly: movingvolume = cast(movingvolume > -800,'like',movingvolume);

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by