Unification ct scan voxel size by using interpolation in Python
I have used interp2
in Matlab, such as the following code, that is part of @rayryeng's answer in: Three dimensional (3D) matrix interpolation in Matlab:
d = size(volume_image)
[X,Y] = meshgrid(1:1/scaleCoeff(2):d(2), 1:1/scaleCoeff(1):d(1));
for ind = z
%Interpolate each slice via interp2
M2D(:,:,ind) = interp2(volume_image(:,:,ind), X, Y);
end
Example of Dimensions:
The image size is 512x512 and the number of slices is 133. So:
volume_image(rows, columns, slices in 3D dimenson) : 512x512x133 in 3D dimenson
X: 288x288
Y: 288x288
scaleCoeff(2): 0.5625
scaleCoeff(1): 0.5625
z = 1 up to 133 ,hence z: 1x133
ind: 1 up to 133
M2D(:,:,ind) finally is 288x288x133 in 3D dimenson
Aslo, Matlabs syntax for size: (rows, columns, slices in 3rd dimenson) and Python syntax for size: (slices in 3rd dim, rows, columns).
However, after convert the Matlab code to Python code occurred an error, ValueError: Invalid length for input z for non rectangular grid
:
for ind in range(0, len(z)+1):
M2D[ind, :, :] = interpolate.interp2d(X, Y, volume_image[ind, :, :]) # ValueError: Invalid length for input z for non rectangular grid
What is wrong? Thank you so much.
python matlab interpolation dicom
|
show 9 more comments
I have used interp2
in Matlab, such as the following code, that is part of @rayryeng's answer in: Three dimensional (3D) matrix interpolation in Matlab:
d = size(volume_image)
[X,Y] = meshgrid(1:1/scaleCoeff(2):d(2), 1:1/scaleCoeff(1):d(1));
for ind = z
%Interpolate each slice via interp2
M2D(:,:,ind) = interp2(volume_image(:,:,ind), X, Y);
end
Example of Dimensions:
The image size is 512x512 and the number of slices is 133. So:
volume_image(rows, columns, slices in 3D dimenson) : 512x512x133 in 3D dimenson
X: 288x288
Y: 288x288
scaleCoeff(2): 0.5625
scaleCoeff(1): 0.5625
z = 1 up to 133 ,hence z: 1x133
ind: 1 up to 133
M2D(:,:,ind) finally is 288x288x133 in 3D dimenson
Aslo, Matlabs syntax for size: (rows, columns, slices in 3rd dimenson) and Python syntax for size: (slices in 3rd dim, rows, columns).
However, after convert the Matlab code to Python code occurred an error, ValueError: Invalid length for input z for non rectangular grid
:
for ind in range(0, len(z)+1):
M2D[ind, :, :] = interpolate.interp2d(X, Y, volume_image[ind, :, :]) # ValueError: Invalid length for input z for non rectangular grid
What is wrong? Thank you so much.
python matlab interpolation dicom
How did you createvolume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would bevolume_image[:, :, ind]
. Also the range is wrong, you want to usefor ind in range(len(z):
.
– Matthieu Brucher
Oct 26 '18 at 8:12
@ Matthieu Brucher: I found out: Matlabs syntax forsize: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax forsize: [z = slices in 3D dim, x = rows, y = columns]
and also, the range offor
is the same as Matlab. I edited my example in the question.
– eli
Oct 26 '18 at 8:58
How did you read your image? You still have an error withlen(z)
and why is z not a vector but a matrix?.
– Matthieu Brucher
Oct 26 '18 at 8:59
@ Matthieu Brucher: I collect the images asvolume_image[i, :, :] = dcm_image.pixel_array
in a loop.z
is number of slices in 3rd dimension.The error is because ofinterp2d
and notlen(z)
.
– eli
Oct 26 '18 at 9:16
You may want to use scikit.image instead.len(z)
is an error, but I would say that the content ofvolume_image
also doesn't allow a good interpolation. But we don't have its content.
– Matthieu Brucher
Oct 26 '18 at 9:24
|
show 9 more comments
I have used interp2
in Matlab, such as the following code, that is part of @rayryeng's answer in: Three dimensional (3D) matrix interpolation in Matlab:
d = size(volume_image)
[X,Y] = meshgrid(1:1/scaleCoeff(2):d(2), 1:1/scaleCoeff(1):d(1));
for ind = z
%Interpolate each slice via interp2
M2D(:,:,ind) = interp2(volume_image(:,:,ind), X, Y);
end
Example of Dimensions:
The image size is 512x512 and the number of slices is 133. So:
volume_image(rows, columns, slices in 3D dimenson) : 512x512x133 in 3D dimenson
X: 288x288
Y: 288x288
scaleCoeff(2): 0.5625
scaleCoeff(1): 0.5625
z = 1 up to 133 ,hence z: 1x133
ind: 1 up to 133
M2D(:,:,ind) finally is 288x288x133 in 3D dimenson
Aslo, Matlabs syntax for size: (rows, columns, slices in 3rd dimenson) and Python syntax for size: (slices in 3rd dim, rows, columns).
However, after convert the Matlab code to Python code occurred an error, ValueError: Invalid length for input z for non rectangular grid
:
for ind in range(0, len(z)+1):
M2D[ind, :, :] = interpolate.interp2d(X, Y, volume_image[ind, :, :]) # ValueError: Invalid length for input z for non rectangular grid
What is wrong? Thank you so much.
python matlab interpolation dicom
I have used interp2
in Matlab, such as the following code, that is part of @rayryeng's answer in: Three dimensional (3D) matrix interpolation in Matlab:
d = size(volume_image)
[X,Y] = meshgrid(1:1/scaleCoeff(2):d(2), 1:1/scaleCoeff(1):d(1));
for ind = z
%Interpolate each slice via interp2
M2D(:,:,ind) = interp2(volume_image(:,:,ind), X, Y);
end
Example of Dimensions:
The image size is 512x512 and the number of slices is 133. So:
volume_image(rows, columns, slices in 3D dimenson) : 512x512x133 in 3D dimenson
X: 288x288
Y: 288x288
scaleCoeff(2): 0.5625
scaleCoeff(1): 0.5625
z = 1 up to 133 ,hence z: 1x133
ind: 1 up to 133
M2D(:,:,ind) finally is 288x288x133 in 3D dimenson
Aslo, Matlabs syntax for size: (rows, columns, slices in 3rd dimenson) and Python syntax for size: (slices in 3rd dim, rows, columns).
However, after convert the Matlab code to Python code occurred an error, ValueError: Invalid length for input z for non rectangular grid
:
for ind in range(0, len(z)+1):
M2D[ind, :, :] = interpolate.interp2d(X, Y, volume_image[ind, :, :]) # ValueError: Invalid length for input z for non rectangular grid
What is wrong? Thank you so much.
python matlab interpolation dicom
python matlab interpolation dicom
edited Oct 26 '18 at 20:04
eli
asked Oct 26 '18 at 8:07
elieli
666
666
How did you createvolume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would bevolume_image[:, :, ind]
. Also the range is wrong, you want to usefor ind in range(len(z):
.
– Matthieu Brucher
Oct 26 '18 at 8:12
@ Matthieu Brucher: I found out: Matlabs syntax forsize: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax forsize: [z = slices in 3D dim, x = rows, y = columns]
and also, the range offor
is the same as Matlab. I edited my example in the question.
– eli
Oct 26 '18 at 8:58
How did you read your image? You still have an error withlen(z)
and why is z not a vector but a matrix?.
– Matthieu Brucher
Oct 26 '18 at 8:59
@ Matthieu Brucher: I collect the images asvolume_image[i, :, :] = dcm_image.pixel_array
in a loop.z
is number of slices in 3rd dimension.The error is because ofinterp2d
and notlen(z)
.
– eli
Oct 26 '18 at 9:16
You may want to use scikit.image instead.len(z)
is an error, but I would say that the content ofvolume_image
also doesn't allow a good interpolation. But we don't have its content.
– Matthieu Brucher
Oct 26 '18 at 9:24
|
show 9 more comments
How did you createvolume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would bevolume_image[:, :, ind]
. Also the range is wrong, you want to usefor ind in range(len(z):
.
– Matthieu Brucher
Oct 26 '18 at 8:12
@ Matthieu Brucher: I found out: Matlabs syntax forsize: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax forsize: [z = slices in 3D dim, x = rows, y = columns]
and also, the range offor
is the same as Matlab. I edited my example in the question.
– eli
Oct 26 '18 at 8:58
How did you read your image? You still have an error withlen(z)
and why is z not a vector but a matrix?.
– Matthieu Brucher
Oct 26 '18 at 8:59
@ Matthieu Brucher: I collect the images asvolume_image[i, :, :] = dcm_image.pixel_array
in a loop.z
is number of slices in 3rd dimension.The error is because ofinterp2d
and notlen(z)
.
– eli
Oct 26 '18 at 9:16
You may want to use scikit.image instead.len(z)
is an error, but I would say that the content ofvolume_image
also doesn't allow a good interpolation. But we don't have its content.
– Matthieu Brucher
Oct 26 '18 at 9:24
How did you create
volume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would be volume_image[:, :, ind]
. Also the range is wrong, you want to use for ind in range(len(z):
.– Matthieu Brucher
Oct 26 '18 at 8:12
How did you create
volume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would be volume_image[:, :, ind]
. Also the range is wrong, you want to use for ind in range(len(z):
.– Matthieu Brucher
Oct 26 '18 at 8:12
@ Matthieu Brucher: I found out: Matlabs syntax for
size: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax for size: [z = slices in 3D dim, x = rows, y = columns]
and also, the range of for
is the same as Matlab. I edited my example in the question.– eli
Oct 26 '18 at 8:58
@ Matthieu Brucher: I found out: Matlabs syntax for
size: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax for size: [z = slices in 3D dim, x = rows, y = columns]
and also, the range of for
is the same as Matlab. I edited my example in the question.– eli
Oct 26 '18 at 8:58
How did you read your image? You still have an error with
len(z)
and why is z not a vector but a matrix?.– Matthieu Brucher
Oct 26 '18 at 8:59
How did you read your image? You still have an error with
len(z)
and why is z not a vector but a matrix?.– Matthieu Brucher
Oct 26 '18 at 8:59
@ Matthieu Brucher: I collect the images as
volume_image[i, :, :] = dcm_image.pixel_array
in a loop. z
is number of slices in 3rd dimension.The error is because of interp2d
and not len(z)
.– eli
Oct 26 '18 at 9:16
@ Matthieu Brucher: I collect the images as
volume_image[i, :, :] = dcm_image.pixel_array
in a loop. z
is number of slices in 3rd dimension.The error is because of interp2d
and not len(z)
.– eli
Oct 26 '18 at 9:16
You may want to use scikit.image instead.
len(z)
is an error, but I would say that the content of volume_image
also doesn't allow a good interpolation. But we don't have its content.– Matthieu Brucher
Oct 26 '18 at 9:24
You may want to use scikit.image instead.
len(z)
is an error, but I would say that the content of volume_image
also doesn't allow a good interpolation. But we don't have its content.– Matthieu Brucher
Oct 26 '18 at 9:24
|
show 9 more comments
2 Answers
2
active
oldest
votes
In MATLAB, interp2
has as arguments:
result = interp2(input_x, input_y, input_z, output_x, output_y)
You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2)
and input_y = 1:size(input_z,1)
.
In Python, scipy.interpolate.interp2
is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:
f = scipy.interpolate.interp2(input_x, input_y, input_z)
result = f(output_x, output_y)
Following the example from the documentation, I get to something like this:
from scipy import interpolate
x = np.arange(0, volume_image.shape[2])
y = np.arange(0, volume_image.shape[1])
f = interpolate.interp2d(x, y, volume_image[ind, :, :])
xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
M2D[ind, :, :] = f(xnew, ynew)
[Code not tested, please let me know if there are errors.]
There is an error:ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of512x512
to288x288
.
– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition ofscaleCoeff
. Make usre thatxnew
andynew
each have 288 elements.
– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because ofscaleCoeff
. My problem is solved. Thank you so much.
– eli
Oct 26 '18 at 20:56
add a comment |
You might be interested in scipy.ndimage.zoom
. If you are interpolating from one regular grid to another, it is much faster and easier to use than scipy.interpolate.interp2d
.
See this answer for an example:
https://stackoverflow.com/a/16984081/1295595
You'd probably want something like:
import scipy.ndimage as ndimage
M2D = ndimage.zoom(volume_image, (1, scaleCoeff[0], scaleCoeff[1])
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53004228%2funification-ct-scan-voxel-size-by-using-interpolation-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In MATLAB, interp2
has as arguments:
result = interp2(input_x, input_y, input_z, output_x, output_y)
You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2)
and input_y = 1:size(input_z,1)
.
In Python, scipy.interpolate.interp2
is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:
f = scipy.interpolate.interp2(input_x, input_y, input_z)
result = f(output_x, output_y)
Following the example from the documentation, I get to something like this:
from scipy import interpolate
x = np.arange(0, volume_image.shape[2])
y = np.arange(0, volume_image.shape[1])
f = interpolate.interp2d(x, y, volume_image[ind, :, :])
xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
M2D[ind, :, :] = f(xnew, ynew)
[Code not tested, please let me know if there are errors.]
There is an error:ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of512x512
to288x288
.
– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition ofscaleCoeff
. Make usre thatxnew
andynew
each have 288 elements.
– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because ofscaleCoeff
. My problem is solved. Thank you so much.
– eli
Oct 26 '18 at 20:56
add a comment |
In MATLAB, interp2
has as arguments:
result = interp2(input_x, input_y, input_z, output_x, output_y)
You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2)
and input_y = 1:size(input_z,1)
.
In Python, scipy.interpolate.interp2
is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:
f = scipy.interpolate.interp2(input_x, input_y, input_z)
result = f(output_x, output_y)
Following the example from the documentation, I get to something like this:
from scipy import interpolate
x = np.arange(0, volume_image.shape[2])
y = np.arange(0, volume_image.shape[1])
f = interpolate.interp2d(x, y, volume_image[ind, :, :])
xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
M2D[ind, :, :] = f(xnew, ynew)
[Code not tested, please let me know if there are errors.]
There is an error:ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of512x512
to288x288
.
– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition ofscaleCoeff
. Make usre thatxnew
andynew
each have 288 elements.
– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because ofscaleCoeff
. My problem is solved. Thank you so much.
– eli
Oct 26 '18 at 20:56
add a comment |
In MATLAB, interp2
has as arguments:
result = interp2(input_x, input_y, input_z, output_x, output_y)
You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2)
and input_y = 1:size(input_z,1)
.
In Python, scipy.interpolate.interp2
is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:
f = scipy.interpolate.interp2(input_x, input_y, input_z)
result = f(output_x, output_y)
Following the example from the documentation, I get to something like this:
from scipy import interpolate
x = np.arange(0, volume_image.shape[2])
y = np.arange(0, volume_image.shape[1])
f = interpolate.interp2d(x, y, volume_image[ind, :, :])
xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
M2D[ind, :, :] = f(xnew, ynew)
[Code not tested, please let me know if there are errors.]
In MATLAB, interp2
has as arguments:
result = interp2(input_x, input_y, input_z, output_x, output_y)
You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2)
and input_y = 1:size(input_z,1)
.
In Python, scipy.interpolate.interp2
is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:
f = scipy.interpolate.interp2(input_x, input_y, input_z)
result = f(output_x, output_y)
Following the example from the documentation, I get to something like this:
from scipy import interpolate
x = np.arange(0, volume_image.shape[2])
y = np.arange(0, volume_image.shape[1])
f = interpolate.interp2d(x, y, volume_image[ind, :, :])
xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
M2D[ind, :, :] = f(xnew, ynew)
[Code not tested, please let me know if there are errors.]
answered Oct 26 '18 at 20:04
Cris LuengoCris Luengo
19.2k51947
19.2k51947
There is an error:ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of512x512
to288x288
.
– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition ofscaleCoeff
. Make usre thatxnew
andynew
each have 288 elements.
– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because ofscaleCoeff
. My problem is solved. Thank you so much.
– eli
Oct 26 '18 at 20:56
add a comment |
There is an error:ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of512x512
to288x288
.
– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition ofscaleCoeff
. Make usre thatxnew
andynew
each have 288 elements.
– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because ofscaleCoeff
. My problem is solved. Thank you so much.
– eli
Oct 26 '18 at 20:56
There is an error:
ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of 512x512
to 288x288
.– eli
Oct 26 '18 at 20:35
There is an error:
ValueError: could not broadcast input array from shape (288,1024) into shape (288,288)
. I want to resize an image with the size of 512x512
to 288x288
.– eli
Oct 26 '18 at 20:35
@eli: Maybe I misinterpreted your definition of
scaleCoeff
. Make usre that xnew
and ynew
each have 288 elements.– Cris Luengo
Oct 26 '18 at 20:44
@eli: Maybe I misinterpreted your definition of
scaleCoeff
. Make usre that xnew
and ynew
each have 288 elements.– Cris Luengo
Oct 26 '18 at 20:44
Yes, it was because of
scaleCoeff
. My problem is solved. Thank you so much.– eli
Oct 26 '18 at 20:56
Yes, it was because of
scaleCoeff
. My problem is solved. Thank you so much.– eli
Oct 26 '18 at 20:56
add a comment |
You might be interested in scipy.ndimage.zoom
. If you are interpolating from one regular grid to another, it is much faster and easier to use than scipy.interpolate.interp2d
.
See this answer for an example:
https://stackoverflow.com/a/16984081/1295595
You'd probably want something like:
import scipy.ndimage as ndimage
M2D = ndimage.zoom(volume_image, (1, scaleCoeff[0], scaleCoeff[1])
add a comment |
You might be interested in scipy.ndimage.zoom
. If you are interpolating from one regular grid to another, it is much faster and easier to use than scipy.interpolate.interp2d
.
See this answer for an example:
https://stackoverflow.com/a/16984081/1295595
You'd probably want something like:
import scipy.ndimage as ndimage
M2D = ndimage.zoom(volume_image, (1, scaleCoeff[0], scaleCoeff[1])
add a comment |
You might be interested in scipy.ndimage.zoom
. If you are interpolating from one regular grid to another, it is much faster and easier to use than scipy.interpolate.interp2d
.
See this answer for an example:
https://stackoverflow.com/a/16984081/1295595
You'd probably want something like:
import scipy.ndimage as ndimage
M2D = ndimage.zoom(volume_image, (1, scaleCoeff[0], scaleCoeff[1])
You might be interested in scipy.ndimage.zoom
. If you are interpolating from one regular grid to another, it is much faster and easier to use than scipy.interpolate.interp2d
.
See this answer for an example:
https://stackoverflow.com/a/16984081/1295595
You'd probably want something like:
import scipy.ndimage as ndimage
M2D = ndimage.zoom(volume_image, (1, scaleCoeff[0], scaleCoeff[1])
answered Nov 14 '18 at 1:37
craqcraq
3691621
3691621
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53004228%2funification-ct-scan-voxel-size-by-using-interpolation-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How did you create
volume_image
? Usually, in Python, arrays are stored in C order, not F order like Matlab, so it would bevolume_image[:, :, ind]
. Also the range is wrong, you want to usefor ind in range(len(z):
.– Matthieu Brucher
Oct 26 '18 at 8:12
@ Matthieu Brucher: I found out: Matlabs syntax for
size: (x = rows, y = columns, z = slices in 3D dimenson)
and Python syntax forsize: [z = slices in 3D dim, x = rows, y = columns]
and also, the range offor
is the same as Matlab. I edited my example in the question.– eli
Oct 26 '18 at 8:58
How did you read your image? You still have an error with
len(z)
and why is z not a vector but a matrix?.– Matthieu Brucher
Oct 26 '18 at 8:59
@ Matthieu Brucher: I collect the images as
volume_image[i, :, :] = dcm_image.pixel_array
in a loop.z
is number of slices in 3rd dimension.The error is because ofinterp2d
and notlen(z)
.– eli
Oct 26 '18 at 9:16
You may want to use scikit.image instead.
len(z)
is an error, but I would say that the content ofvolume_image
also doesn't allow a good interpolation. But we don't have its content.– Matthieu Brucher
Oct 26 '18 at 9:24