void closing(char A[MAX_MN][MAX_MN+1], char B[MAX_B][MAX_B+1], char C[MAX_MN][MAX_MN+1]) { char temp[MAX_MN][MAX_MN+1]; dilation(A, B, temp); erosion(temp, B, C); }
static void bothat( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length ) { const Int size = Int(input.size()); std::vector<ValueT> closing; dilation(input,output,struc_elem_length); erosion(output,closing,struc_elem_length); for ( Int index = 0; index < size; ++ index ) { output[index] = input[index] - closing[index]; } return; }
Imlib_Image opening(Imlib_Image *source_image,double thresh,luminance_t lt,int n) { int i; Imlib_Image temp_image1, temp_image2; /* erosion n times */ imlib_context_set_image(*source_image); temp_image1 = temp_image2 = imlib_clone_image(); for(i=0; i<n; i++) { temp_image2 = erosion(&temp_image1, thresh, lt); imlib_context_set_image(temp_image1); imlib_free_image(); temp_image1 = temp_image2; } /* dilation n times */ for(i=0; i<n; i++) { temp_image2 = dilation(&temp_image1, thresh, lt); imlib_context_set_image(temp_image1); imlib_free_image(); temp_image1 = temp_image2; } return temp_image2; }
void ProcessFrame(uint8 *pInputImg) { uint8_t thres = (uint8_t)data.ipc.state.nThreshold; /* if the threshold is 0, the otsu algorithm is used */ if(thres == 0) { thres = otsu(IMAGE(GRAYSCALE)); } data.ipc.state.thres_calc = thres; /* make the threshold image */ thresh(IMAGE(THRESHOLD), IMAGE(GRAYSCALE), thres); /* dilation */ dilation(IMAGE(DILATION), IMAGE(THRESHOLD)); /* erosion */ erosion(IMAGE(EROSION), IMAGE(DILATION)); /* do the region labeling stuff */ region_labeling(IMAGE(LABELIMG)); }
closing(unsigned char **image_pixel,int height,int width) { dilation(image_pixel,height,width); erosion(image_pixel,height,width); }
int main(int argc, char* argv[]) { // check if the argument number is valid if (argc < 4) { std::cerr << "Usage: " << argv[0] << " input-file output-file [operations] [parameters]" << std::endl; return 1; } // check if the input file is valid std::ifstream input(argv[1]); if (!input) { std::cerr << "Can not open the grades in file " << argv[1] << std::endl; return 1; } // read in the image std::vector<std::string> image; read_in_image(input, image); if (image.size() == 0) { std::cout << "Cannot import the image " << argv[1] << ". Try again please. " << std::endl; return 1; } std::ofstream output(argv[2]); // the output file std::string op = argv[3]; // the operation name if (op.compare("replace") == 0 && argc == 6) { // replace char before = argv[4][0]; char after = argv[5][0]; replace(image, before, after); } else if (op.compare("dilation") == 0 && (argc == 5 || argc == 6)) { // dilation operation char color = argv[4][0]; if (argc == 5) { // When plus-signed structing element dilation(image, color, false); } else if (argc == 6 && std::string(argv[5]).compare("square") == 0) { // when square-signed structing element dilation(image, color, true); } else { std::cerr << "Usage: " << argv[0] << " input-file output-file dilation color [square]" << std::endl; return 1; } } else if (op.compare("erosion") == 0 && (argc == 6 || argc == 7)) { // erosion operation char color = argv[4][0]; char pixel = argv[5][0]; if (argc == 6) { // When plus-signed structing element erosion(image, color, pixel, false); } else if (argc == 7 && std::string(argv[6]).compare("square") == 0) { // when square-signed structing element erosion(image, color, pixel, true); } else { std::cerr << "Usage: " << argv[0] << " input-file output-file erosion pixel [square]" << std::endl; return 1; } } else if (op.compare("floodfill") == 0 && argc == 7) { // floodfill operation int row = atoi(argv[4]); int col = atoi(argv[5]); if (!isValid(image, row, col)) { std::cerr << "Error: invalid arguments " << row << " and " << col << std::endl; return 1; } char filler = argv[6][0]; flood_fill(image, row, col, filler); } else { // invalid input command std::cerr << "Invalid command." << std::endl; std::cerr << "Usage: " << argv[0] << " input-file output-file [operations] [parameters]" << std::endl; return 1; } // write the modified image to a file if (output.is_open()) { output_image(image, output); output.close(); } else { std::cerr << "Cannot output to " << argv[3] << std::endl; return 1; } return 0; }
int main(int argc, char* argv[]) { //error messagea if (argc != 5 and argc != 6 and argc != 7) { std::cerr << "arguments can not be fit in" << argv[0] ; return 1; } std::string row; std::ifstream myFile(argv[1]); if (!myFile.good()) { std::cerr << "The file is not correct!" << argv[1] << "\n"; } //std::string row; //input each row to a string std::vector<std::string> inputs; //Input vectors to hold all the points while (std::getline(myFile, row)) { inputs.push_back(row); } std::cout << "The input:"<<std::endl; //print out the input for (unsigned int i = 0 ; i < inputs.size() ; ++i ) { std::cout << inputs[i] << std::endl; } ///////////starts to do the replace, dialation, erosion and floodfill std::vector<std::string> results; // create a vector called results for later print out // dilation if (argc == 5) { results = dilation(inputs, argv[4][0]); for (unsigned int i = 0 ; i < results.size() ; ++i ) { std::cout << results[i] << std::endl; } } //replace+erosion if (argc == 6) { std::string a = "replace"; std::string b = "erosion"; if (!a.compare(argv[3])) { results = replace(inputs, argv[4][0], argv[5][0]); } if (!b.compare(argv[3])) { results = erosion(inputs, argv[4][0], argv[5][0]); } } //floodfill if (argc ==7) { //convert the string in arguments to integers int r = atoi(argv[4]); int c = atoi(argv[5]); char temp = argv[6][0]; floodfill(inputs, r, c, temp); results = inputs; } std::cout << "The output:"<<std::endl; //print out the output for (unsigned int i = 0 ; i < results.size() ; ++i ) { std::cout << results[i] << std::endl; } //output to a file std::ofstream outputs; outputs.open(argv[2]); for (unsigned int i = 0 ; i < results.size() ; ++i) { outputs << results[i] <<"\n" ; } outputs.close(); return 0; }
void EndogenousSalienceThread::run(){ /* * Identify the modal hue and saturation values in the logpolar image, * segment the cartesian image accordingly, * identify the largest blob, extract the coordinates of the centroid, * package everything with the encoder values & the focal length values in a bottle, * and send it out (typically to the egosphere module) * send out the segmented image out for viewing */ unsigned char pixel_value; if (debug) { printf("endogenousSalienceThread: parameters are %d %d %d %d\n\n", *hueTolerance, *saturationTolerance, *hueBins, *saturationBins); } /* create the histogram */ if (hsHistogram == NULL) { hsHistogram = new DVhs_histogram(*hueBins, *saturationBins); } while (isStopping() != true) { // the thread continues to run until isStopping() returns true /* * Step 1: grab cartesian and logpolar images and copy images to local format * ========================================================================== */ if (debug) cout << "endogenousSalienceThread: grabbing images " << endl; do { cartesianImage = cartesianImagePortIn->read(true); } while ((cartesianImage == NULL) && (isStopping() != true)); if (isStopping()) break; // abort this loop to avoid make sure we don't continue and possibly use NULL images do { logpolarImage = logpolarImagePortIn->read(true); } while ((logpolarImage == NULL)&& (isStopping() != true)); if (isStopping()) break; // abort this loop to avoid make sure we don't continue and possibly use NULL images width = cartesianImage->width(); height = cartesianImage->height(); depth = 3; if (debug) printf("endogenousSalienceThread: width = %d, height = %d, depth = %d\n",width, height, depth); if (cartesianInput == NULL) { cartesianInput = new DVimage(width, height, depth); } if (segmentedOutput == NULL) { segmentedOutput = new DVimage(width, height, depth); } if (tempImageA == NULL) { tempImageA = new DVimage(width, height, depth); } if (tempImageB == NULL) { tempImageB = new DVimage(width, height, depth); } width = logpolarImage->width(); height = logpolarImage->height(); depth = 3; if (debug) printf("endogenousSalienceThread: width = %d, height = %d, depth = %d\n",width, height, depth); if (logpolarInput == NULL) { logpolarInput = new DVimage(width, height, depth); } width = cartesianImage->width(); height = cartesianImage->height(); for (x=0; x<width; x++) { for (y=0; y<height; y++) { rgbPixel = cartesianImage->safePixel(x,y); cartesianInput->put_pixel(x, y, rgbPixel.r, 0); cartesianInput->put_pixel(x, y, rgbPixel.g, 1); cartesianInput->put_pixel(x, y, rgbPixel.b, 2); } } width = logpolarImage->width(); height = logpolarImage->height(); for (x=0; x<width; x++) { for (y=0; y<height/2; y++) { // ***************************** only use the top half, i.e. the fovea rgbPixel = logpolarImage->safePixel(x,y); logpolarInput->put_pixel(x, y, rgbPixel.r, 0); logpolarInput->put_pixel(x, y, rgbPixel.g, 1); logpolarInput->put_pixel(x, y, rgbPixel.b, 2); } } /* * Step 2: Identify the modal hue and saturation values in the logpolar image * ========================================================================== * */ if (debug) cout << "endogenousSalienceThread: generating histogram " << endl; colour_histogram(logpolarInput, hsHistogram); if (true && debug) cout << "endogenousSalienceThread: identifying histogram mode " << endl; hsHistogram->hsMode(&hueMode, &saturationMode); /* * Step 3: segment the cartesian image * ===================================== */ if (debug) cout << "endogenousSalienceThread: performing segmentation " << endl; hueRange = (*hueTolerance * (float) 360) / (float) (100); // convert percentage to real values saturationRange = (*saturationTolerance) / (float) (100); colour_segmentation(cartesianInput, hueMode, saturationMode, hueRange, saturationRange, segmentedOutput); // Step 4: filter the colour_segmentation by performing an morphological opening // ============================================================================= if (debug) cout << "endogenousSalienceThread: post-segmentation filtering - morphological opening " << endl; if (*filterRadius > 0) { erosion (segmentedOutput, *filterRadius, tempImageA); dilation(tempImageA, *filterRadius, tempImageB); } // Step 5: filter the colour segmentation by performing a medial distance transform // ============================================================================= if (debug) cout << "endogenousSalienceThread: post-segmentation filtering - medial distance transform" << endl; distance_from_background_transform(tempImageB, segmentedOutput); segmentedOutput->contrast_stretch(); /* * Step 6: copy the segmented image to the salience image in YARP format and write it out * ====================================================================================== */ if (debug) cout << "endogenousSalienceThread: sending images " << endl; width = cartesianImage->width(); height = cartesianImage->height(); ImageOf<PixelRgb> &salienceImage = salienceImagePortOut->prepare(); salienceImage.resize(width,height); for (x=0; x < width; x++) { for (y=0; y < height; y++) { segmentedOutput->get_pixel(x, y, &pixel_value, 0); rgbPixel.r=pixel_value; segmentedOutput->get_pixel(x, y, &pixel_value, 1); rgbPixel.g=pixel_value; segmentedOutput->get_pixel(x, y, &pixel_value, 2); rgbPixel.b=pixel_value; salienceImage(x,y) = rgbPixel; } } if (isStopping()) break; // abort this loop to avoid make sure we don't continue and possibly use NULL images salienceImagePortOut->write(); } }
void test_run() { laplacian_filter(x, y, Nq); dilation(x, z, Nq); erosion(z, w, Nq); }