Unexpected behaviour of sliceViewer 'SliceDirection'
Mostrar comentarios más antiguos
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 comentario
Jacques
el 29 de Jun. de 2025
Respuestas (1)
Kautuk Raj
el 3 de Jul. de 2025
0 votos
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.
Categorías
Más información sobre Morphological Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!