DR :: Batch ? very first version


Enough for internship. Now is a time for ?SENIOR PROJECT?.

/* More Explanation Will Be HERE ! */

/* Sorry too lazy to update anything ^^ */

1. Original Image

2. After Contrast Enhancement

3. After Region Growing Segmentation

4. Detect Disc and Extudate

5. Edge Detection

6. PCA

7. NN

8. Vessel / Hae / Mo

9. Morphological

10. Result

//---------------------------------------------------------------------------
#include <iostream>
#include <direct.h>
#include <stdlib.h>
#include <Jpeg.hpp>
#include <string>
#pragma hdrstop

// User Define Header File --------------------------------------------------
#include "library/ReadTiff.hpp"
#include "library/ReadTiffTags.hpp"

#include "imgprocessing/Contrast.h"
#include "imgprocessing/DiscExudate.h"
#include "imgprocessing/EdgeDetection.h"
#include "imgprocessing/Exudate.h"
#include "imgprocessing/morphological.h"
#include "imgprocessing/NN.h"
#include "imgprocessing/PCA.h"
#include "imgprocessing/validation.h"
#include "imgprocessing/Vessels.h"

// Function Definition ------------------------------------------------------
void printUsageMSG();
void GetCurrentPath(char* buffer);
void Contrast(Graphics::TBitmap *input_img, Graphics::TBitmap *mask);

//---------------------------------------------------------------------------
#pragma argsused

using namespace std;

int main(int argc, char* argv[]){

 char CurrentPath[_MAX_PATH];                  // Current System Path
 string imgFolder = "retinopathy-data";        // Default folder that store images
 string startDir;                              // Start Directiry Path
 string imgPath;                               // Whole Images Path
 string imgExt;                                // images files extension
 string inputImg;                              // User input images from command line
 string maskPath;                               // Path for retina mask images
 Graphics::TBitmap *input_img, *mask;
 TJPEGImage *jpeg;

 // Check command line argument
 if(argc == 1){
 printUsageMSG();
 getchar();
 exit(0);
 }
 cout << "nn" ;

 // Get Path
 inputImg = argv[1];
 GetCurrentPath(CurrentPath);
 startDir = CurrentPath;
 imgPath  = startDir + "" + imgFolder + "" + inputImg;
 maskPath = startDir + "" + "images"  + "" + "retinamask.bmp";
 cout << "mask path is  :: " << maskPath << endl;
 cout << "image path is :: " << imgPath  << endl << endl;

 cout << "!!!!!!!! HERE !!!!!!!!";

 // Load Mask
 if(mask != NULL){
 delete mask;
 }
 mask = new Graphics::TBitmap;
 mask->LoadFromFile(maskPath.c_str());

 // Load Image
 // --- 1. Get image extension
 imgExt = inputImg.substr(inputImg.find(".")+1);
 // --- 2. Load Image
 if(input_img != NULL){
 delete input_img;
 }
 input_img = new Graphics::TBitmap;
 try{
 // Read JPG
 if(imgExt == "jpg" || imgExt == "JPG" || imgExt == "jpeg" || imgExt == "JPEG" ){
 cout << "Loading JPG....";
 jpeg = new TJPEGImage;
 jpeg->LoadFromFile(imgPath.c_str());
 input_img->Assign(jpeg);
 }
 // Read TIFF
 else if(imgExt == "tiff" || imgExt == "TIFF"){
 cout << "Loading TIFF....";
 //LoadTiffFromFile(imgPath.c_str(), bitmap1);
 //bitmap1->PixelFormat = pf24bit;
 }
 // Read BMP
 else if(imgExt == "bmp"  || imgExt == "BMP"){
 cout << "Loading BMP....";
 input_img->LoadFromFile(imgPath.c_str());
 }
 }
 catch(...){
 cout << "Error: Read file error." << endl;
 }

 //Process
 Contrast(input_img,mask);

 // Cleanup
 delete (input_img);
 delete (mask);

 getchar();
 return 0;
}
//---------------------------------------------------------------------------
void GetCurrentPath(char* buffer){
 getcwd(buffer, _MAX_PATH);
}
void printUsageMSG(){
 cout << "Retina Screening Phrase 1 :: Batch" << endl;
 cout << "usage: DR_Batch_project <images_name>" << endl;
 cout << "note : Support only .tiff .jpg .bmp" << endl << endl;
}
void Contrast(Graphics::TBitmap *input_img, Graphics::TBitmap *mask){

 Graphics::TBitmap *c_input_img, *c_mask;

 cout << "!!!!!ENTERING CONTRAST FUNCTION!!!!!";

 // create & assign contrast image variable
 if(c_input_img != NULL){
 delete c_input_img;
 }
 c_input_img = new Graphics::TBitmap;
 c_input_img->Assign(input_img);

 if(c_mask != NULL){
 delete c_mask;
 }
 c_mask = new Graphics::TBitmap;
 c_mask->Assign(mask);

 // 1. Contrast Enhancement
 cout << "Processing :: Contrast Enhancement....";
 if (CContrastBitmap != NULL){
 delete CContrastBitmap;
 }
 CContrastBitmap = new Graphics::TBitmap;
 Contrast_colour(c_input_img, c_mask);
 cout << "Done....";
 CContrastBitmap->SaveToFile("C1.bmp");
 cout << "Saved";

 if(MyVarianceC != NULL) delete MyVarianceC;
 MyVarianceC = new Graphics::TBitmap;
 if (CEdgeBitmap != NULL) delete CEdgeBitmap;
 CEdgeBitmap = new Graphics::TBitmap;
 if (CPCABitmap != NULL) delete CPCABitmap;
 CPCABitmap = new Graphics::TBitmap;
 if (CNNBitmap != NULL) delete CNNBitmap;
 CNNBitmap = new Graphics::TBitmap;
 if (CVesselBitmap != NULL) delete CVesselBitmap;
 CVesselBitmap = new Graphics::TBitmap;
 if (CMorphoBitmap != NULL) delete CMorphoBitmap;
 CMorphoBitmap = new Graphics::TBitmap;
 if (CExudateBitmap != NULL) delete CExudateBitmap;
 CExudateBitmap = new Graphics::TBitmap;
 if (CHaemorBitmap != NULL) delete CHaemorBitmap;
 CHaemorBitmap = new Graphics::TBitmap;
 if(DiscExudateBMP != NULL) delete DiscExudateBMP;
 DiscExudateBMP = new Graphics::TBitmap;
 if(CValidateExudate != NULL) delete CValidateExudate;
 CValidateExudate = new Graphics::TBitmap;

}

One response to “DR :: Batch ? very first version”

  1. ammii Avatar

    ขอโทษนะคะ ไม่ทราบว่าใช้libraryอะไรเหรอคะ?? ลอง search หาใน google แล้วไม่เจอนะคะ ><" ขอบคุณนะคะ ^^"

    #include "imgprocessing/EdgeDetection.h"
    #include "imgprocessing/morphological.h"
    #include "imgprocessing/NN.h"
    #include "imgprocessing/PCA.h"

Leave a Reply

Your email address will not be published. Required fields are marked *