Effacer les filtres
Effacer les filtres

How do I make sure two imported .nrrd files are plotted in the same coordinate frame when using nrrdread?

5 vues (au cours des 30 derniers jours)
Hi all,
I have an MRI volume and a segmentation from a scene in 3D Slicer, and I need to do some analysis in MATLAB. In Slicer, the two entities overlay each other properly, but when I import them into MATLAB things don't align anymore. In Slicer, all transforms have been hardened.
There are a lot of properties in the .nrrd headers (shown below my code), and I'm not sure if I need to handle any of them explicitly or if MATLAB knows what to do with it automatically when I use 'nrrdread'.
My code is as follows:
vol_A = double(nrrdread('path/to/nrrd_file_A'));
vol_B = double(nrrdread('path/to/nrrd_file_B'));
%% Transform stuff needs to go here so vol_A and vol_B are aligned %%
% I imagine I need to use imrotate3 and imtranslate, but can't figure out
% what values to use
% Find the non-zero indices in volume B and mark them in volume A with a value of 1024
% so we can see them easily
[x,y,z] = ind2sub(size(vol_B), find(vol_B));
for i = 1:size(x, 1)
vol_A(x,y,z) = 1024;
end
% Create alphamap and colormap to make the 1024 values stick out in bright
% red
alpha = [0, 0, 0.02, 0.037, 0.01, 0.02, 1];
color = [0 0 0; 43 0 0; 103 37 20; 199 155 97; 216 213 201; 255 255 255; 255 0 0]/255;
intensity = [0, 40, 80, 120, 800, 1000, 1024];
queryPoints = linspace(min(intensity), max(intensity), 256);
alphamap = interp1(intensity, alpha, queryPoints);
colormap = interp1(intensity, color, queryPoints);
% Display the combined volume
volshow(vol_A, Colormap=colormap, Alphamap=alphamap);
Header file for .nrrd file A
NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: unsigned char
dimension: 3
space: left-posterior-superior
sizes: 224 224 250
space directions: (0,0.96363633871077981,0) (0,0,-0.96363633871077981) (-0.95999905383251116,0,0)
kinds: domain domain domain
encoding: gzip
space origin: (102.84023291351068,-109.67142070125807,102.80120362861894)
Segment0_Color:=0.501961 0.682353 0.501961
Segment0_ColorAutoGenerated:=1
Segment0_Extent:=1 93 107 167 77 161
Segment0_ID:=Segment_1
Segment0_LabelValue:=1
Segment0_Layer:=0
Segment0_Name:=Lesion
Segment0_NameAutoGenerated:=0
Segment0_Tags:=Segmentation.Status:inprogress|TerminologyEntry:Segmentation category and type - 3D Slicer General Anatomy list~SRT^T-D0050^Tissue~SRT^T-D0050^Tissue~^^~Anatomic codes - DICOM master list~^^~^^|
Segmentation_ContainedRepresentationNames:=Binary labelmap|
Segmentation_ConversionParameters:=Collapse labelmaps|1|Merge the labelmaps into as few shared labelmaps as possible 1 = created labelmaps will be shared if possible without overwriting each other.&Compute surface normals|1|Compute surface normals. 1 (default) = surface normals are computed. 0 = surface normals are not computed (slightly faster but produces less smooth surface display).&Crop to reference image geometry|0|Crop the model to the extent of reference geometry. 0 (default) = created labelmap will contain the entire model. 1 = created labelmap extent will be within reference image extent.&Decimation factor|0.0|Desired reduction in the total number of polygons. Range: 0.0 (no decimation) to 1.0 (as much simplification as possible). Value of 0.8 typically reduces data set size by 80% without losing too much details.&Fractional labelmap oversampling factor|1|Determines the oversampling of the reference image geometry. All segments are oversampled with the same value (value of 1 means no oversampling).&Joint smoothing|0|Perform joint smoothing.&Oversampling factor|1|Determines the oversampling of the reference image geometry. If it's a number, then all segments are oversampled with the same value (value of 1 means no oversampling). If it has the value "A", then automatic oversampling is calculated.&Reference image geometry|0;0;0.959999053832511;-102.84023291351069;-0.96363633871078;0;0;109.67142070125809;0;-0.96363633871078;0;102.80120362861896;0;0;0;1;0;223;0;223;0;249;|Image geometry description string determining the geometry of the labelmap that is created in course of conversion. Can be copied from a volume, using the button.&Smoothing factor|0|Smoothing factor. Range: 0.0 (no smoothing) to 1.0 (strong smoothing).&Threshold fraction|0.5|Determines the threshold that the closed surface is created at as a fractional value between 0 and 1.&
Segmentation_MasterRepresentation:=Binary labelmap
Segmentation_ReferenceImageExtentOffset:=0 0 0
Header file for .nrrd file B
NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: double
dimension: 3
space: left-posterior-superior
sizes: 256 256 250
space directions: (-0.039238430422844015,-0.87955116855925952,-0.022804295261199786) (-0.066398172718697565,0.025722025661534198,-0.8778380308883027) (0.95606014202768841,-0.040745765711721449,-0.073508674494034767)
kinds: domain domain domain
endian: little
encoding: gzip
space origin: (-105.56082078190065,113.93606355056932,123.98372655856895)

Réponses (0)

Catégories

En savoir plus sur 3-D Volumetric Image Processing dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by