/*****************************************************************************/ /* * File name: MImProcessing.c * * Synopsis: This program uses different image processing primitives to * determine the number of cell nuclei that are larger than * a certain size in an image of a tissue sample. */ #include #include /* Target MIL image file specifications. */ #define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Cell.mim") #define IMAGE_THRESHOLD_VALUE 128L #define IMAGE_SMALL_PARTICLE_RADIUS 2L void main(void) { MIL_ID MilApplication, /* Application identifier. */ MilSystem, /* System identifier. */ MilDisplay, /* Display identifier. */ MilImage, /* Image buffer identifier. */ MilExtremeResult; /* Extreme result buffer identifier. */ long MaxLabelNumber; /* Highest label value. */ /* Allocate defaults. */ MappAllocDefault(M_SETUP, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL); /* Restore source image and display it. */ MbufRestore(IMAGE_FILE, MilSystem, &MilImage); MdispSelect(MilDisplay, MilImage); /* Pause to show the original image. */ printf("\nIMAGE PROCESSING:\n"); printf("-----------------\n\n"); printf("This program counts the number of large particles in the image.\n"); printf("Press to continue.\n\n"); getch(); /* Smooth the image to remove noise. */ MimConvolve(MilImage, MilImage, M_SMOOTH); /* Binarize the image so that particles are represented in white and the background in black. */ MimBinarize(MilImage, MilImage, M_LESS_OR_EQUAL, IMAGE_THRESHOLD_VALUE, M_NULL); /* Remove small particles. */ MimOpen(MilImage, MilImage, IMAGE_SMALL_PARTICLE_RADIUS, M_BINARY); /* Pause to show the remaining particle(s). */ printf("These particles have been extracted from the original image.\n"); printf("Press to continue.\n\n"); getch(); /* Label the image. */ MimLabel(MilImage, MilImage, M_DEFAULT); /* The largest label value corresponds to the number of particles in the image. */ MimAllocResult(MilSystem, 1L, M_EXTREME_LIST, &MilExtremeResult); MimFindExtreme(MilImage, MilExtremeResult, M_MAX_VALUE); MimGetResult(MilExtremeResult, M_VALUE, &MaxLabelNumber); /* Multiply the labeling result to augment the gray level of the particles. */ MimArith(MilImage, 256L/MaxLabelNumber, MilImage, M_MULT_CONST); /* Display the result in pseudo-color. */ MdispLut(MilDisplay, M_PSEUDO); /* Print results. */ printf("There were %ld large particles in the original image.\n", MaxLabelNumber); printf("Press to end.\n\n"); getch(); /* Free all allocations. */ MimFree(MilExtremeResult); MbufFree(MilImage); MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL); }