write_ibex_mat

PURPOSE ^

WRITE_IBEX_MAT: write images to ibex mat file format

SYNOPSIS ^

function write_ibex_mat(fname, fmdl, imgs, frame_rate)

DESCRIPTION ^

 WRITE_IBEX_MAT:  write images to ibex mat file format
  write_ibex_mat(fname, fmdl, imgr)
    fname - file name to write to 
    fmdl  - the fmdl to use, including lung regions
    imgr  - the reconstructed image requence
    frame_rate - frame rate of acq data


 Limitations, imgr must be a 2D 32×32 image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function write_ibex_mat(fname, fmdl, imgs, frame_rate)
0002 % WRITE_IBEX_MAT:  write images to ibex mat file format
0003 %  write_ibex_mat(fname, fmdl, imgr)
0004 %    fname - file name to write to
0005 %    fmdl  - the fmdl to use, including lung regions
0006 %    imgr  - the reconstructed image requence
0007 %    frame_rate - frame rate of acq data
0008 %
0009 %
0010 % Limitations, imgr must be a 2D 32×32 image
0011 
0012 % (C) 2024 Andy Adler. License: GPL version 2 or version 3
0013 % $Id: write_ibex_mat.m 7002 2024-11-24 13:11:35Z aadler $
0014 
0015 [llROI, rlROI, thROI] = get_ROIs(fmdl);
0016 imgs(isnan(imgs))= 0;
0017 data = create_data(imgs, frame_rate, thROI, llROI, rlROI );
0018 save(fname,'data');
0019 
0020 function [llung_ROI, rlung_ROI, thorax_ROI] = get_ROIs(fmdl);
0021     lmi = length(fmdl.mat_idx);
0022     img = mk_image(fmdl, 1); % background conductivity
0023     if lmi==1;
0024       error('Need mat_idx regions to segment lungs');
0025     elseif lmi==2; % one lung, must cut
0026       img.elem_data(fmdl.mat_idx{2}) = 0.3; % lungs
0027     else % at least two lungs
0028       img.elem_data(fmdl.mat_idx{2}) = 0.3; % lungs
0029       img.elem_data(fmdl.mat_idx{3}) = 0.3; % lungs
0030     end
0031     img.calc_colours.npoints = 32;
0032     ROI = calc_slices(img,1);
0033     if ~(size(ROI)==[32,32])
0034        error('image size must be 32×32'); 
0035     end
0036      
0037     thorax_ROI= ~isnan(ROI);
0038     lung_ROI  = thorax_ROI & (ROI==0.3);
0039     xpts = linspace(-1,1,32);
0040     rlung_ROI = lung_ROI & (xpts<0);
0041     llung_ROI = lung_ROI & (xpts>0);
0042 
0043 function data = create_data(imgs, FR, thorax_ROI, llung_ROI, rlung_ROI);
0044     data.imageRate = FR;
0045 
0046     data.patient.ROI.Inside =thorax_ROI*100; % to scale it up to 100
0047     data.patient.ROI.RightLung =rlung_ROI*100;
0048     data.patient.ROI.LeftLung =llung_ROI*100;
0049     data.patient.ROI.Heart =zeros(size(imgs,1),size(imgs,2));
0050 
0051     % put to dummy because they are missing
0052     data.patient.halfChest = 'NaN';
0053     data.patient.height = 'NaN';
0054     data.patient.weight = 'NaN';
0055     data.patient.gender = 'NaN';
0056 
0057     data.measurement.Position.transversal = zeros (1,size(imgs,3));
0058     data.measurement.Position.longitudinal = zeros (1,size(imgs,3));
0059     data.measurement.ImageQuality = 100*ones(1,size(imgs,3));
0060     data.measurement.ElectrodeQuality = zeros(size(imgs,3),32);
0061     data.measurement.ZeroRef = imgs;
0062 
0063     data.injctionPattern= 'NaN';
0064     data.SensorBelt.NumEl= 'NaN';
0065 
0066     data.measurement.CompositValue=squeeze(sum(sum(imgs,2),1));
0067 
0068

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005