MEDCON(3)
π NAME π
okay so bestie, medcon β (X)MedCon's C Library - Medical Image Conversion Utility. it's giving medical image conversion realness β¨π
π LIBRARY π
(X)MedCon C library ( libmdc.a ) β the whole library vibe, fr fr π«Ά
β¨ SYNOPSIS β¨
okay so literally the include first, no cap:
#include "medcon.h"
π Important Global Variables π
these are the globals you're gonna be seeing everywhere, bestie. slay:
char prefix[MDC_MAX_PREFIX+1]; /* prefix for new filenames */
/* command-line input data */
char *mdc_arg_files[]; /* pointers to input files */
int mdc_arg_convs[]; /* conversions selected */
int mdc_arg_total[]; /* total files & conversions*/
/* options set at command-line */
char MDC_INSTITUTION[]; /* name of institution */
Int8 MDC_COLOR_MAP; /* gray color palette selected */
Int8 MDC_PADDING_MODE; /* resized image padding mode */
Int8 MDC_ANLZ_SPM; /* Analyze/SPM scaling factor */
Int8 MDC_ANLZ_OPTIONS; /* Analyze/SPM request params */
Int8 MDC_DICOM_MOSAIC_ENABLED; /* DICOM: mosaic support enabled */
Int8 MDC_DICOM_MOSAIC_FORCED; /* DICOM: mosaic preset forced */
Int8 MDC_DICOM_MOSAIC_DO_INTERL; /* DICOM: mosaic forced interlaced */
Int8 MDC_DICOM_MOSAIC_FIX_VOXEL; /* DICOM: mosaic fix voxel sizes */
Int8 MDC_DICOM_WRITE_IMPLICIT; /* DICOM: write little implicit */
Int8 MDC_DICOM_WRITE_NOMETA; /* DICOM: write without meta header */
Int8 MDC_DICOM_WRITE_ENCAP_UNCOMP; /* DICOM: write encap. uncompressed */
Int8 MDC_FORCE_RESCALE; /* user specified slope/intercept */
Int8 MDC_FORCE_CONTRAST; /* user specified centre/width */
Int8 MDC_INFO; /* default print header info */
Int8 MDC_INTERACTIVE; /* interactive read of raw file */
Int8 MDC_CONVERT; /* image conversion requested */
Int8 MDC_EXTRACT; /* extract images */
Int8 MDC_RENAME; /* rename base filename */
Int8 MDC_ECHO_ALIAS; /* echo alias name based on ID's */
Int8 MDC_EDIT_FI; /* edit FILEINFO struct */
Int8 MDC_PIXELS; /* print specified pix values */
Int8 MDC_PIXELS_PRINT_ALL; /* print all pix values */
Int8 MDC_NEGATIVE; /* allow negative pixel values */
Int8 MDC_QUANTIFY; /* quantitation with one factor */
Int8 MDC_CALIBRATE; /* quantitation with two factors */
Int8 MDC_CONTRAST_REMAP; /* apply contrast remapping */
Int8 MDC_DEBUG; /* give debug info */
Int8 MDC_VERBOSE; /* run in verbose mode */
Int8 MDC_GIF_OPTIONS; /* request for extra GIF options */
Int8 MDC_MAKE_GRAY; /* forced remap color to gray scale */
Int8 MDC_DITHER_COLOR; /* apply dither on color reduction */
Int8 MDC_NORM_OVER_FRAMES; /* normalize over images in a frame */
/* instead of all images */
Int8 MDC_SKIP_PREVIEW; /* skip the first (preview) slice */
Int8 MDC_IGNORE_PATH; /* ignore path in INTF data fname */
Int8 MDC_SINGLE_FILE; /* write INTF as single file */
Int8 MDC_FORCE_INT; /* force integer pixels */
Int8 MDC_INT16_BITS_USED; /* bits to use for Int16 type */
Int8 MDC_TRUE_GAP; /* spacing = true gap/overlap */
Int8 MDC_ALIAS_NAME; /* use alias name based on ID's */
Int8 MDC_PREFIX_DISABLED; /* prevent the prefix in names */
Int8 MDC_PREFIX_ACQ; /* use acquisition number as prefix */
Int8 MDC_PREFIX_SER; /* use series number as prefix */
Int8 MDC_PATIENT_ANON; /* make patient anonymous */
Int8 MDC_PATIENT_IDENT; /* give patient identification */
Int8 MDC_FILE_OVERWRITE; /* allow file overwriting */
Int8 MDC_FILE_STDIN; /* input from stdin stream */
Int8 MDC_FILE_STDOUT; /* output to stdout stream */
Int8 MDC_FILE_SPLIT; /* split up file in parts */
Int8 MDC_FILE_STACK; /* stack up files */
Int8 MDC_FLIP_HORIZONTAL; /* flip horizontal (x) */
Int8 MDC_FLIP_VERTICAL; /* flip vertical (y) */
Int8 MDC_SORT_REVERSE; /* reverse sorting */
Int8 MDC_SORT_CINE_APPLY; /* cine apply sorting */
Int8 MDC_SORT_CINE_UNDO; /* cine undo sorting */
Int8 MDC_MAKE_SQUARE; /* make square image */
Int8 MDC_CROP_IMAGES; /* crop image dimensions */
Int8 MDC_RESLICE; /* reslice images (tra, sag, cor) */
Int8 MDC_FRMT_INPUT; /* format used for stdin */
Int8 MDC_ECAT6_SORT; /* ECAT sort order */
Int8 MDC_FALLBACK_FRMT; /* fallback read format */
π¦ Important Defines π¦
these are the format and color-map constants, iykyk:
/* representation of supported formats */
#define MDC_FRMT_NONE 0 /* unsupported format */
#define MDC_FRMT_RAW 1 /* Read Interactive */
/* Write RAW Binary */
#define MDC_FRMT_ASCII 2 /* Write RAW Ascii */
#define MDC_FRMT_GIF 3 /* GIF89a or GIF87a */
#define MDC_FRMT_ACR 4 /* Acr/Nema 2.0 (Papyrus) */
#define MDC_FRMT_INW 5 /* INW (RUG) */
#define MDC_FRMT_ECAT6 6 /* Siemens/CTI ECAT 6.4 */
#define MDC_FRMT_ECAT7 7 /* Siemens/CTI ECAT 7.2 */
#define MDC_FRMT_INTF 8 /* Interfile v3.3 */
#define MDC_FRMT_ANLZ 9 /* Analyze (SPM) */
#define MDC_FRMT_DICM 10 /* DICOM 3.0 */
#define MDC_FRMT_PNG 11 /* PNG */
#define MDC_FRMT_CONC 12 /* Concorde uPet */
#define MDC_FRMT_NIFTI 13 /* NIfTI-1 */
#define MDC_MAX_FMTS 14 /* total + 1 */
/* supported color maps */
#define MDC_MAP_PRESENT 0 /* 256 RGB colormap */
#define MDC_MAP_GRAY 1 /* grayscale colormap */
#define MDC_MAP_INVERTED 2 /* inverted colormap */
#define MDC_MAP_RAINBOW 3 /* rainbow colormap */
#define MDC_MAP_COMBINED 4 /* combined colormap */
#define MDC_MAP_HOTMETAL 5 /* hotmetal colormap */
#define MDC_MAP_LOADED 6 /* extern LUT loaded */
πΈ Important Structures πΈ
and here come the structs, bestie. so many little data babies π«Ά:
/* static related data */
typedef struct Static_Data_t {
char label[MDC_MAXSTR]; /* label name of image */ /* Ant/Post */
float total_counts; /* total counts in image */
float image_duration; /* duration of image (ms) */
Int16 start_time_hour; /* start time hour */
Int16 start_time_minute; /* start time minute */
Int16 start_time_second; /* start time second */
} STATIC_DATA;
/* gated SPECT related data */
typedef struct Gated_Data_t {
Int8 gspect_nesting; /* gated spect nesting */
float nr_projections; /* number of projections */
float extent_rotation; /* extent of rotation */
float study_duration; /* study duration (ms) */
float image_duration; /* image duration (ms) */
float time_per_proj; /* time per proj (ms) */
float window_low; /* lower limit (ms) */
float window_high; /* higher limit (ms) */
float cycles_observed; /* cardiac cycles observed*/
float cycles_acquired; /* cardiac cycles acquired*/
} GATED_DATA;
/* acquisition data */
typedef struct Acquisition_Data_t {
Int16 rotation_direction; /* direction of rotation */
Int16 detector_motion; /* type detector motion */
float rotation_offset; /* centre rotation offset */
float radial_position; /* radial position */
float angle_start; /* start angle (interfile)*/ /* 180 - dicom */
float angle_step; /* angular step */
float scan_arc; /* angular range */
} ACQ_DATA;
/* dynamic data */
typedef struct Dynamic_Data_t {
Uint32 nr_of_slices; /* images in time frame */
float time_frame_start; /* start time frame (ms) */
float time_frame_delay; /* delay this frame (ms) */
float time_frame_duration; /* duration frame (ms) */
float delay_slices; /* delay each slice (ms) */
} DYNAMIC_DATA;
/* bed data */
typedef struct Bed_Data_t {
float hoffset; /* horizon. position (mm) */
float voffset; /* vertical position (mm) */
} BED_DATA;
/* images related data */
typedef struct Image_Data_t {
/* ** general data ** */
Uint32 width,height; /* image dimension */
Int16 bits,type; /* bits/pixel & datatype */
Uint16 flags; /* extra flag */
double min, max; /* min/max pixelvalue */
double qmin, qmax; /* quantified min/max */
double fmin, fmax; /* min/max in whole frame */
double qfmin, qfmax; /* in whole frame (quant) */
float rescale_slope; /* rescale slope */ /* auto filled */
float rescale_intercept; /* rescale intercept */ /* auto filled */
Uint32 frame_number; /* part of frame (1-based)*/ /* auto filled */
float slice_start; /* start of slice (ms) */ /* auto filled */
Uint8 *buf; /* pointer to raw image */
off_t load_location; /* load start in file */
/* ** internal items ** */
Int8 rescaled; /* rescaled image? */
double rescaled_min; /* new rescaled max */
double rescaled_max; /* new rescaled min */
double rescaled_fctr; /* new rescaled fctr */
double rescaled_slope; /* new rescaled slope */
double rescaled_intercept; /* new rescaled intercept */
/* ** ecat64 items ** / Int16 quant_units; / quantification units / Int16 calibr_units; / calibration units / float quant_scale; / quantification scale / float calibr_fctr; / calibration factor / float intercept; / scale intercept / float pixel_xsize; / pixel size X (mm) / float pixel_ysize; / pixel size Y (mm) / float slice_width; / slice width (mm) / float recon_scale; / recon magnification */
/* ** Acr/Nema items ** */
float image_pos_dev[3]; /* image posit dev (mm) / float image_orient_dev[6]; / image orient dev (mm) / float image_pos_pat[3]; / image posit pat (mm) / float image_orient_pat[6]; / image orient pat (mm) / float slice_spacing; / space btw centres (mm) / float ct_zoom_fctr; / CT image zoom factor */
/* ** Miscellaneous ** */
STATIC_DATA sdata; / extra static entries / / just one */
unsigned char plugb; / like to attach here? */
} IMG_DATA;
so that's `IMG_DATA` wrapped up π β she's holding the ecat64 quant/calibration numbers, the ACR/NEMA geometry stuff, and a lil `plugb` pointer for whatever you wanna bolt on. iconic.
now the big one. say hi to `FILEINFO` π β the file information struct, aka the main character of this whole library:
/* the file information struct */ typedef struct File_Info_t {
FILE ifp; / pointer to input file / FILE *ifp_raw; / pointer to raw input / FILE *ofp; / pointer to output file / FILE *ofp_raw; / pointer to raw output / char ipath[MDC_MAX_PATH+1]; / path to input file / char opath[MDC_MAX_PATH+1]; / path to output file / char *idir; / dir to input file / char *odir; / dir to output file / char *ifname; / name of input file / char *ofname; / name of output file / int iformat; / format of input file / int oformat; / format of output file / int modality; / modality / Int8 rawconv; / FRMT_RAW | FRMT_ASCII / Int8 endian; / endian of file / Int8 compression; / file compression / Int8 truncated; / truncated file? / Int8 diff_type; / images with diff type? / Int8 diff_size; / images with diff size? / Int8 diff_scale; / images with diff scale?/ Uint32 number; / total number of images / / private / Uint32 mwidth,mheight; / global max dimensions / Int16 bits, type; / global bits & datatype / Int16 dim[MDC_MAX_DIMS]; / [0] = # of dimensions / / [1] = X-dim (pixels) / / [2] = Y-dim (pixels) / / [3] = Z-dim (planes) / / [4] = (frames) / / [5] = (gates) / / [6] = (beds) / / ... / / values must be 1-based */
float pixdim[MDC_MAX_DIMS]; /* [0] = # of dimensions / / [1] = X-dim (mm) / / [2] = Y-dim (mm) / / [3] = Z-dim (mm) / / [4] = time (ms) / / ... / double glmin, glmax; / global min/max value / double qglmin, qglmax; / quantified min/max */
Int8 contrast_remapped; /* contrast remap applied / float window_centre; / contrast window centre / float window_width; / contrast window width */
Int8 slice_projection; /* projection of images / Int8 pat_slice_orient; / combined flag / char pat_pos[MDC_MAXSTR]; / patient position / char pat_orient[MDC_MAXSTR]; / patient orientation / char patient_sex[MDC_MAXSTR]; / sex of patient / char patient_name[MDC_MAXSTR];/ name of patient / char patient_id[MDC_MAXSTR]; / id of patient / char patient_dob[MDC_MAXSTR]; / birth of patient / / YYYYMMDD / float patient_weight; / weight of patient (kg) / float patient_height; / height of patient (m) / char operator_name[MDC_MAXSTR];/ name of scan operator / char study_descr[MDC_MAXSTR]; / study description / char study_id[MDC_MAXSTR]; / study id / Int16 study_date_day; / day of study (1-31) / Int16 study_date_month; / month of study (1-12) / Int16 study_date_year; / year of study / Int16 study_time_hour; / hour of study / Int16 study_time_minute; / minute of study / Int16 study_time_second; / second of study / Int16 dose_time_hour; / hour of dose start / Int16 dose_time_minute; / minute of dose start / Int16 dose_time_second; / second of dose start / Int32 nr_series; / series number / Int32 nr_acquisition; / acquisition number / Int32 nr_instance; / instance number / Int16 acquisition_type; / acquisition type / Int16 planar; / planar or tomo ? / Int16 decay_corrected; / decay corrected ? / Int16 flood_corrected; / flood corrected ? */
Int16 reconstructed; /* reconstructed ? / char recon_method[MDC_MAXSTR]; / reconstruction method */
char institution[MDC_MAXSTR]; /* name of institution / char manufacturer[MDC_MAXSTR]; / name of manufacturer / char series_descr[MDC_MAXSTR]; / series description / char radiopharma[MDC_MAXSTR]; / radiopharmaceutical / char filter_type[MDC_MAXSTR]; / filter type / char organ_code[MDC_MAXSTR]; / organ / char isotope_code[MDC_MAXSTR]; / isotope / float isotope_halflife; / isotope halflife (sec) / float injected_dose; / amount injected (MBq) / float gantry_tilt; / gantry tilt */
Uint8 map; /* indexed 256 colormap / Uint8 palette[768]; / global palette / char *comment; / whatever comment / Uint32 comm_length; / length of comment */
Uint32 gatednr; /* number of gated entries*/ /* now 0 or 1 / GATED_DATA *gdata; / array of GATED_DATA */
Uint32 acqnr; /* number acq. entries / ACQ_DATA *acqdata; / array ACQ_DATA entries */
Uint32 dynnr; /* number of time frames / DYNAMIC_DATA *dyndata; / array of DYNAMIC_DATA */
Uint32 bednr; /* number bed positions / BED_DATA * beddata; / array of BED_DATA */
IMG_DATA image; / array IMG_DATA images */
MOD_INFO mod; / modality related info */
unsigned char pluga; / want to attach stuff? */
} FILEINFO;
<rainbow>she's everything. she's literally everything.</rainbow> ππ
okay let's do a lil vibe check on what `FILEINFO` is packing, because it's a LOT and every single one of these matters:
- <pink>`ifp`, `ifp_raw`, `ofp`, `ofp_raw`</pink> β the four file pointers: input, raw input, output, raw output. yes bestie, raw gets its own lane π
- <pink>`ipath` / `opath`</pink> β paths to the input and output files, sized `MDC_MAX_PATH+1`
- <pink>`idir`, `odir`, `ifname`, `ofname`</pink> β pointers to the input dir, output dir, input filename and output filename
- <pink>`iformat` / `oformat`</pink> β the format of the input file and of the output file
- <pink>`modality`</pink> β the modality, periodt
- <pink>`rawconv`</pink> β `FRMT_RAW | FRMT_ASCII`
- <pink>`endian`</pink> β the endianness of the file
- <pink>`compression`</pink> β file compression
- <pink>`truncated`</pink> β is the file truncated? π
- <pink>`diff_type`, `diff_size`, `diff_scale`</pink> β flags for images with differing type, size, or scale. the chaos trio π
- <pink>`number`</pink> β total number of images (marked `private`, iykyk)
- <pink>`mwidth`, `mheight`</pink> β the global max dimensions
- <pink>`bits`, `type`</pink> β the global bits and datatype
- <pink>`dim[MDC_MAX_DIMS]`</pink> β the dimensions array. listen: `[0]` is the **number of dimensions**, `[1]` is X-dim in pixels, `[2]` is Y-dim in pixels, `[3]` is Z-dim in planes, `[4]` is frames, `[5]` is gates, `[6]` is beds, and so on. and the values **must be 1-based**. no zero-based shenanigans here, she said what she said π«
- <pink>`pixdim[MDC_MAX_DIMS]`</pink> β the same shape but for physical size: `[0]` is number of dimensions, `[1]` X-dim in mm, `[2]` Y-dim in mm, `[3]` Z-dim in mm, `[4]` time in ms, and `...`
- <pink>`glmin`, `glmax`</pink> β global min/max value
- <pink>`qglmin`, `qglmax`</pink> β the quantified min/max
- <pink>`contrast_remapped`</pink> β was contrast remap applied?
- <pink>`window_centre`, `window_width`</pink> β contrast window centre and width
- <pink>`slice_projection`</pink> β projection of images
- <pink>`pat_slice_orient`</pink> β a combined flag
- <pink>`pat_pos`, `pat_orient`</pink> β patient position and patient orientation
- <pink>`patient_sex`, `patient_name`, `patient_id`, `patient_dob`</pink> β sex, name, id, and birth of the patient. the dob is `YYYYMMDD` format, bestie, don't freestyle it
- <pink>`patient_weight`</pink> β weight of patient, in kg
- <pink>`patient_height`</pink> β height of patient, in m
- <pink>`operator_name`</pink> β name of the scan operator
- <pink>`study_descr`, `study_id`</pink> β study description and study id
- <pink>`study_date_day` (1-31), `study_date_month` (1-12), `study_date_year`</pink> β the study date, split into pieces
- <pink>`study_time_hour`, `study_time_minute`, `study_time_second`</pink> β the study time
- <pink>`dose_time_hour`, `dose_time_minute`, `dose_time_second`</pink> β when the dose started
- <pink>`nr_series`, `nr_acquisition`, `nr_instance`</pink> β series number, acquisition number, instance number
- <pink>`acquisition_type`</pink> β acquisition type
- <pink>`planar`</pink> β planar or tomo?
- <pink>`decay_corrected`</pink> β decay corrected?
- <pink>`flood_corrected`</pink> β flood corrected?
- <pink>`reconstructed`</pink> β reconstructed?
- <pink>`recon_method`</pink> β reconstruction method
- <pink>`institution`, `manufacturer`</pink> β name of the institution, name of the manufacturer
- <pink>`series_descr`</pink> β series description
- <pink>`radiopharma`</pink> β the radiopharmaceutical
- <pink>`filter_type`</pink> β filter type
- <pink>`organ_code`</pink> β the organ
- <pink>`isotope_code`</pink> β the isotope
- <pink>`isotope_halflife`</pink> β isotope halflife, in sec
- <pink>`injected_dose`</pink> β amount injected, in MBq
- <pink>`gantry_tilt`</pink> β gantry tilt
- <pink>`map`</pink> β indexed 256 colormap
- <pink>`palette[768]`</pink> β the global palette
- <pink>`comment`, `comm_length`</pink> β whatever comment, and its length
- <pink>`gatednr`, `gdata`</pink> β number of gated entries (currently 0 or 1) and the array of `GATED_DATA`
- <pink>`acqnr`, `acqdata`</pink> β number of acquisition entries and the array of `ACQ_DATA` entries
- <pink>`dynnr`, `dyndata`</pink> β number of time frames and the array of `DYNAMIC_DATA`
- <pink>`bednr`, `beddata`</pink> β number of bed positions and the array of `BED_DATA`
- <pink>`image`</pink> β the array of `IMG_DATA` images
- <pink>`mod`</pink> β modality related info
- <pink>`pluga`</pink> β "want to attach stuff?" β yes queen, attach away β¨
---
## π Important Functions π
okay so here's the whole squad of functions, laid out exactly like the header file gives them. every signature, verbatim, because we do not play with function signatures in this house:
void MdcInit (void); void MdcFinish (void);
int MdcHandleArgs ( FILEINFO *fi, int argc, char *argv[], int MAXFILES ); void MdcPrintUsage ( char *pgrname );
int MdcOpenFile ( FILEINFO *fi, char *path ); int MdcReadFile ( FILEINFO *fi, int filenr, char *(*ReadFunc)(FILEINFO *fi) ); int MdcWriteFile ( FILEINFO *fi, int format, int prefixnr, char *(*WriteFunc)(FILEINFO *fi) );
void MdcInitFI ( FILEINFO *fi, char *path ); void MdcFreeIDs ( FILEINFO *fi ); void MdcCleanUpFI ( FILEINFO *fi ); void MdcResetIDs ( FILEINFO *fi ); void MdcPrintFI ( FILEINFO *fi ); void MdcCloseFile ( FILE *fp ); void MdcSplitPath ( char path[], char **dir, char **fname ); int MdcGetFrmt ( FILEINFO *fi );
void MdcGetColorMap ( int map, Uint8 palette[] ); char *MdcImagesPixelFiddle( FILEINFO *fi);
void MdcPrntMesg ( char *fmt, ... ); void MdcPrntWarn ( char *fmt, ... ); void MdcPrntErr ( int code, char *fmt, ... );
char *MdcReadACR ( FILEINFO *fi ); char *MdcReadANLZ ( FILEINFO *fi ); char *MdcReadCONC ( FILEINFO *fi ); char *MdcReadDICM ( FILEINFO *fi ); char *MdcReadECAT6 ( FILEINFO *fi ); char *MdcReadECAT7 ( FILEINFO *fi ); char *MdcReadGIF ( FILEINFO *fi ); char *MdcReadINTF ( FILEINFO *fi ); char *MdcReadINW ( FILEINFO *fi ); char *MdcReadNIFTI ( FILEINFO *fi ); char *MdcReadPNG ( FILEINFO *fi ); char *MdcReadRAW ( FILEINFO *fi );
char *MdcWriteACR ( FILEINFO *fi ); char *MdcWriteANLZ ( FILEINFO *fi ); char *MdcWriteCONC ( FILEINFO *fi ); char *MdcWriteDICM ( FILEINFO *fi ); char *MdcWriteECAT6 ( FILEINFO *fi ); char *MdcWriteECAT7 ( FILEINFO *fi ); char *MdcWriteGIF ( FILEINFO *fi ); char *MdcWriteINTF ( FILEINFO *fi ); char *MdcWriteINW ( FILEINFO *fi ); char *MdcWriteNIFTI ( FILEINFO *fi ); char *MdcWritePNG ( FILEINFO *fi ); char *MdcWriteRAW ( FILEINFO *fi );
quick rundown of the groups so you know who's who π«Ά:
- <mint>`MdcInit` / `MdcFinish`</mint> β open the whole thing up, and shut it all down. the alpha and the omega.
- <mint>`MdcHandleArgs`, `MdcPrintUsage`</mint> β argument wrangling and usage printing. the ones that handle the group chat drama of `argc`/`argv` (with `MAXFILES` in the mix).
- <mint>`MdcOpenFile`, `MdcReadFile`, `MdcWriteFile`</mint> β opening, reading, and writing files. note that read and write take a function pointer (`ReadFunc` / `WriteFunc` each taking a `FILEINFO *fi`), and write also wants a `format` and a `prefixnr`.
- <mint>`MdcInitFI`, `MdcFreeIDs`, `MdcCleanUpFI`, `MdcResetIDs`, `MdcPrintFI`, `MdcCloseFile`, `MdcSplitPath`, `MdcGetFrmt`</mint> β the `FILEINFO` housekeeping crew. init it, free the IDs, clean it up, reset the IDs, print it, close a file pointer, split a path into dir + fname, and sniff out the format.
- <mint>`MdcGetColorMap`, `MdcImagesPixelFiddle`</mint> β colormap fetching (gimme a `map` and a `palette[]`) and the pixel fiddling. yes the function is literally called `MdcImagesPixelFiddle`, we don't make the rules π
- <mint>`MdcPrntMesg`, `MdcPrntWarn`, `MdcPrntErr`</mint> β the printf-style messaging trio (message, warning, error β and error takes a `code` too). all variadic, all with `char *fmt, ...`.
- <mint>`MdcRead*`</mint> β the reader squad: `ACR`, `ANLZ`, `CONC`, `DICM`, `ECAT6`, `ECAT7`, `GIF`, `INTF`, `INW`, `NIFTI`, `PNG`, `RAW`. every one takes a `FILEINFO *fi` and hands you back a `char *`.
- <mint>`MdcWrite*`</mint> β the writer squad, same lineup: `ACR`, `ANLZ`, `CONC`, `DICM`, `ECAT6`, `ECAT7`, `GIF`, `INTF`, `INW`, `NIFTI`, `PNG`, `RAW`. same signature energy β `FILEINFO *fi` in, `char *` out. π₯
# β¨ DESCRIPTION β¨
okay so listen bestie π the (X)MedCon library exists so you can read AND write all the medical image formats without losing your whole entire mind. Like, that's the whole gig. The OG format they tested everything on was <pink>Ecat 6.4</pink> β that's the origin story, the blueprint, the founding mother.
And here's the key thing you need to internalize: the **`FILEINFO`** structure is where *everything* lives. All the interesting parameters, all the pointers to each image β the whole vibe. She's the main character. Everything else is supporting cast. π
So here's your fast intro, no capβ¦
- **`MdcInit()`, `MdcFinish()`** β the very first and very last functions you call when you're using this library, periodt. Currently there are changes happening to the signal handler for floating point exceptions and also to the program's locale, so don't skip them. π«Ά
- **`MdcHandleArgs()`** β the parser for the command-line arguments. The **last** function argument decides the maximum number of input files allowed, and the absolute max is `MDC_MAX_FILES`, which is defined in the library. So don't be out here trying to exceed it, she will not let you. π
- **`MdcPrintUsage()`** β prints the possible (X)MedCon command line options and then terminates the program. It's giving "we're done here." π
- **`MdcOpenFile()`** β initializes the `FILEINFO` struct and opens the file, with or without decompression. Versatile queen. β¨
- **`MdcReadFile()`** β reads that (decompressed) file, either with format autodetection or by trying a fallback format. It initializes a (grayscale) colormap and does the obligated pixel handling. The last argument enables the use of an external read function. π₯
- **`MdcWriteFile()`** β writes a file in the format you supply. The last argument is a number used in the prefix of the output filename β give a **negative** value when a personal prefix was prepared. And yeah, the last argument also enables the use of an external write function. Two jobs, she's multitasking. π
- **`MdcCloseFile()`** β closes the file and sets the pointer to `NULL`. Clean exit, no loose ends. πΈ
- **`MdcInitFI()`** β initializes the `FILEINFO` structure. Fresh start energy. π¦
- **`MdcFreeIDs()`** β cleans the `IMG_DATA` structures by freeing all the allocated memory. Marie Kondo but make it C. π§
- **`MdcCleanUpFI()`** β cleans the `FILEINFO` structure. The routine makes use of `FreeIDs()`. Teamwork honestly. π
- **`MdcResetIDs()`** β resets the `IMG_DATA` structures. This is **necessary after each conversion**, so do not forget it, I'm begging. π
- **`MdcPrintFI()`** β prints the content of the `FILEINFO` structure. Useful for debug purposes. Your little detective moment. π
- **`MdcSplitPath()`** β splits the path in a string into directory and filename. Two for one. βοΈ
- **`MdcGetFrmt()`** β checks the format of the file. For the return value, see the representation of the supported formats under the section `Important Defines`. With the `MDC_INTERACTIVE` variable ON, the function returns `MDC_FRMT_RAW` β see also `MdcReadRAW()`. iykyk. π
- **`MdcGetColorMap()`** β fills a 256 byte RGB palette with the requested grayscale colormap. 256 bytes of pure aesthetic. π
- **`MdcImagesPixelFiddle()`** β performs all the pixel by pixel processes such as swapping bytes, make positive values, quantification, rescaling, filling the `FILEINFO` structure with global & image variables, and checking some important parameters. **This function is required after a file was read!** Not optional, bestie, this one's mandatory. π¨
- **`MdcPrntMesg()`** β prints a message. Argument is a variable parameter list. β¨
- **`MdcPrntWarn()`** β prints a warning. Argument is a variable parameter list. β οΈ
- **`MdcPrntErr()`** β prints an error and quits the program. The **first** argument is the error code. Dramatic exit, iconic. π
- **`MdcReadACR()` - `MdcWriteACR()`** β reads and writes Acr/Nema files. π
- **`MdcReadANLZ()` - `MdcWriteANLZ()`** β reads and writes Analyze (SPM) files. π§
- **`MdcReadCONC()` - `MdcWriteCONC()`** β reads and writes Concorde microPET. π
- **`MdcReadDICM()` - `MdcWriteDICM()`** β reads and writes DICOM files. π
- **`MdcReadECAT6()` - `MdcWriteECAT6()`** β reads and writes ECAT 6.4 files. πΈ
- **`MdcReadECAT7()` - `MdcWriteECAT7()`** β reads and writes ECAT 7.2 files. πΈ
- **`MdcReadGIF()` - `MdcWriteGIF()`** β reads GIF87a & GIF89a, writes annimated GIF89a files. She said annimated, I said annimated, we're all annimated here. π¦
- **`MdcReadINTF()` - `MdcWriteINTF()`** β reads and writes Interfile 3.3 files. β¨
- **`MdcReadINW()` - `MdcWriteINW()`** β reads and writes RUG INW files. π
- **`MdcReadNIFTI()` - `MdcWriteNIFTI()`** β reads and writes NIfTI-1 files. π§
- **`MdcReadPNG()` - `MdcWritePNG()`** β reads and writes PNG files. π
- **`MdcReadRAW()` - `MdcWriteRAW()`** β reads files of an unknown format **interactively**, and writes raw image arrays without header in binary or ascii. Mystery file? She'll figure it out. π
---
# π EXAMPLE π
A sample C-source code to show the usage of the functions. Please, look into the project source code for more details. π
/* filename: testit.c */
#include <stdio.h>
#include "medcon.h"
#define PROG_VERSION "TestIt v2.4"
void NewPrefix(int n) { sprintf(prefix,"my%02d-",n); /* max of MDC_MAX_PREFIX chars (5) */ }
int main(int argc, char argv[]) { FILEINFO fi; int *total = mdc_arg_total; / total arguments of files & conversions / int *convs = mdc_arg_convs; / counter for each conversion format / char *files = mdc_arg_files; /* array of pointers to input filenames / int f, c; / some counters / int t=0; / counter for the output name prefix / int convert, err=MDC_OK; / some variables */
/* check arguments */ if (argc < 2) { printf("%s - %s0,PROG_VERSION,MdcGetLibLongVersion()); printf("0urpose: a simplified example program0); MdcPrintUsage(argv[0]); }
/* init library */ MdcInit();
/* handle MedCon arguments, last argument determines max inputfiles */ if (MdcHandleArgs(&fi,argc,argv,MDC_MAX_FILES) != MDC_OK) MdcPrintUsage(argv[0]);
/* check output/conversion formats */ if (total[MDC_CONVS] == 0) { printf("9s: ERROR : No output format specified0,argv[0]); return(MDC_BAD_CODE); }
/* do the stuff for each input file */ for (f=0; f<total[MDC_FILES]; f++) {
if ((err = MdcOpenFile(&fi, files[f])) != MDC_OK) return(err);
if ((err = MdcReadFile(&fi, f+1, NULL)) != MDC_OK) return(err);
/* do the conversions */ if (total[MDC_CONVS] > 0) {
/* go through conversion formats / for (c=1; c<MDC_MAX_FRMTS; c++) { convert = convs[c]; / write output format when selected */ while (convert -- > 0) { if ((err = MdcWriteFile(&fi, c, t++, NULL)) != MDC_OK) { MdcCleanUpFI(&fi); return(err); } } } }
/* clean up FILEINFO struct */ MdcCleanUpFI(&fi);
}
/* finish library */ MdcFinish();
return(err);
}
---
Example `Makefile` for compiling `testit.c`: π οΈ
filename: Makefile
CC = gcc CCOPTS = -Wall -g CFLAGS = $(CCOPTS)
INCS = xmedcon-config --cflags LIBS = xmedcon-config --libs
testit: testit.c $(CC) $(CFLAGS) $(INCS) -o testit testit.c $(LIBS)
don't forget a <tab> before $(CC). You can lose this with copy/paste
> ok bestie this is the part where I grab you by the shoulders β **don't forget a `<tab>` before `$(CC)`.** You can lose this with copy/paste. Make will simply not respect you otherwise. π
---
# π FILES π
- `/usr/local/xmedcon/include/` β Directory with header files..
- `/usr/local/xmedcon/lib/` β Directory with libraries.
- `/usr/local/xmedcon/bin/` β Directory with executables.
- `/usr/local/xmedcon/man/` β Directory with man-pages.
- `/usr/local/xmedcon/etc/` β Directory with rcfiles.
---
# π SEE ALSO π
`medcon(1)`, `xmedcon(1)`, `xmedcon-config(1)`
`m-acr(4)`, `m-anlz(4)`, `m-gif(4)`, `m-intf(4)`, `m-ecat(4)`, `m-inw(4)`
---
# π AUTHOR π
(X)MedCon project was originally written by <rainbow>Erik Nolf (eNlf)</rainbow> for the former PET-Centre at Ghent University (Belgium). π§πͺβ¨
e-mail: `enlf-at-users.sourceforge.net` www: `http://xmedcon.sourceforge.net`
---
and that's a wrap, bestie!! π this whole page came straight from the `MEDCON(3)` manual β the (X)MedCon library docs β so if you ever need the receipts, that's the footer to cite. go read and write some medical images, you absolute icon. slay, lowkey responsibly. π
ππ¦
π¦ where this page comes from
- debian trixie: libmdc-dev 0.25.1-gtk3+dfsg-1 Β· GPL-2.0-or-later
- fedora 43: xmedcon-devel 0.25.3-1.fc43 Β· LGPL-2.1-or-later AND LicenseRef-Callaway-Copyright-only AND LicenseRef-Callaway-MIT AND LicenseRef-Callaway-BSD and libtiff
- fedora 44: xmedcon-devel 0.25.3-2.fc44 Β· LGPL-2.1-or-later AND LicenseRef-Callaway-Copyright-only AND LicenseRef-Callaway-MIT AND LicenseRef-Callaway-BSD and libtiff
- nixos 26.05: xmedcon 0.26.2
- nixpkgs unstable: xmedcon 0.26.2
- ubuntu questing: libmdc-dev 0.25.1-gtk3+dfsg-1
- ubuntu resolute: libmdc-dev 0.25.1-gtk3+dfsg-1build1 Β· GPL-2.0-or-later
- ubuntu stonking: libmdc-dev 0.26.1-gtk3+dfsg-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms