Unexpected behaviour of sliceViewer 'SliceDirection'

조회 수: 2 (최근 30일)
Jacques
Jacques 2025년 6월 29일
답변: Kautuk Raj 2025년 7월 3일
I'm not really sure how to reconcile the 'SliceDirection' in sliceViewer. Matlab's documentation says SliceDirection = [0 1 0] slices along the second dimension. But this is clearly not the case. In the MWE SliceViewer shows a line in the middle slice, and black everywhere else. I would expect each slice to have a bright spot in the middle. The imshow() outputs the expected result, a single bright pixel.
matlab sliceViewer documentation says:
Character VectorLogical VectorDescription
'X' [1 0 0] Browse in X direction
'Y' [0 1 0] Browse in Y direction
'Z' (default) [0 0 1] Browse in Z direction"
MWE:
clear all; clc;
N = 40;
full_vol = zeros(N, N, N, 'uint8');
full_vol(N/2, :, N/2) = 255;
figure(); sliceViewer(full_vol, 'SliceDirection', [0 1 0], 'SliceNumber', N/2);
figure(); imshow(squeeze(full_vol(:, N/2, :)))
  댓글 수: 1
Jacques
Jacques 2025년 6월 29일
Please correct me if there is a mistake here, but I'm thinking the problem was:
It was a misunderstanding of the convention (using [x y z] for 'SliceDirection' makes it confusing).
Using 'SliceDirection' [0 1 0] will slice along the first dimension, because matlab defines the first dimension as y, the second dimension as x and the third as z.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kautuk Raj
Kautuk Raj 2025년 7월 3일
Hello @Jacques,
This is arising from how MATLAB indexes arrays and how sliceViewer interprets the 'SliceDirection' parameter. In MATLAB, a 3D array is indexed as (row, column, page), which corresponds to (Y, X, Z).
When you use 'SliceDirection', [0 1 0], you are moving through the first dimension (Y, or rows), so each slice is an X-Z plane at a fixed Y. In your example, only the slice at Y = N/2 (i.e., SliceNumber = N/2) shows the line you set; all other slices are black.
So, your code is behaving as expected according to MATLAB's conventions.

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by