Conversion matlab code to python code

4 visualizaciones (últimos 30 días)
hyounwook jung
hyounwook jung el 3 de Abr. de 2019
Comentada: Rik el 3 de Abr. de 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 comentarios
Guillaume
Guillaume el 3 de Abr. de 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 el 3 de Abr. de 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);

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by