Conversion matlab code to python code

4 ビュー (過去 30 日間)
hyounwook jung
hyounwook jung 2019 年 4 月 3 日
コメント済み: Rik 2019 年 4 月 3 日
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
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
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 ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by