Conversion matlab code to python code
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Guillaume
2019-4-3
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
2019-4-3
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);
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!