void TransFuncEditorIntensityPet::maxBoxChanged(int value) {
    if (value-1 > currentRange_.x) {
        //increment minimum of upper spin when minimum was reached and we are above lower range
        if (value == upperThresholdSpin_->minimum())
            upperThresholdSpin_->setMinimum(value - 1);

        //update maximum of lower spin
        lowerThresholdSpin_->blockSignals(true);
        lowerThresholdSpin_->setMaximum(value);
        lowerThresholdSpin_->blockSignals(false);
    }
    //increment value of lower spin when it equals value of upper spin
    if (value == lowerThresholdSpin_->value()) {
        lowerThresholdSpin_->blockSignals(true);
        lowerThresholdSpin_->setValue(value - 1);
        lowerThresholdSpin_->blockSignals(false);
    }

    //update doubleSlider to new maxValue
    float sliderMax = (value - currentRange_.x) / static_cast<float>(currentRange_.y - currentRange_.x);
    doubleSlider_->blockSignals(true);
    doubleSlider_->setMaxValue(sliderMax);
    doubleSlider_->blockSignals(false);

    //apply threshold to both transfer functions
    applyThreshold();
    updateTransferFunction();
}
Ejemplo n.º 2
0
int main()
    {
    char fileName[80];
    int _ret_val_0;
    sprintf(fileName, "%s/%s", DATA_PATH, INPUT_FILE);
    input_dsp_arg(fileName, image, N * N, 1);
#pragma polca def BLOCK_ABS
    {
    int thresholdValue = T;
    {
    int c;
    int r;
    int aux;
    for (r = 0; r < N; r++)
        {
    for (c = 0; c < N; c++)
        {
    aux = applyThreshold(image[r][c], thresholdValue);
    result[r][c] = aux;
    }
    }
    0;
    }
    }
    sprintf(fileName, "%s/output.dsp", DATA_PATH);
    output_dsp_arg(fileName, result, N * N, 1);
    _ret_val_0 = 0;
    return _ret_val_0;
    }
Ejemplo n.º 3
0
void TransFunc1DRampEditor::upperThresholdSpinChanged(int value) {
    if (value-1 > 0) {
        //increment minimum of upper spin when minimum was reached and we are above lower range
        if (value == upperThresholdSpin_->minimum())
            upperThresholdSpin_->setMinimum(value-1);

        //update maximum of lower spin
        lowerThresholdSpin_->blockSignals(true);
        lowerThresholdSpin_->setMaximum(value);
        lowerThresholdSpin_->blockSignals(false);
    }
    //increment value of lower spin when it equals value of upper spin
    if (value == lowerThresholdSpin_->value()) {
        lowerThresholdSpin_->blockSignals(true);
        lowerThresholdSpin_->setValue(value-1);
        lowerThresholdSpin_->blockSignals(false);
    }

    //update doubleSlider to new maxValue
    doubleSlider_->blockSignals(true);
    doubleSlider_->setMaxValue(value / static_cast<float>(maximumIntensity_));
    doubleSlider_->blockSignals(false);

    //apply threshold to transfer function
    applyThreshold();
}
void TransFuncEditorIntensityPet::resetThresholds() {
    ranges_.clear();
    currentRange_ = tgt::ivec2(0, maximumIntensity_);
    oldThreshold_ = tgt::vec2(0.f, 1.f);

    //reset spinboxes to default
    lowerThresholdSpin_->blockSignals(true);
    lowerThresholdSpin_->setRange(0, maximumIntensity_ - 1);
    lowerThresholdSpin_->setValue(0);
    lowerThresholdSpin_->blockSignals(false);
    upperThresholdSpin_->blockSignals(true);
    upperThresholdSpin_->setRange(1, maximumIntensity_);
    upperThresholdSpin_->setValue(maximumIntensity_);
    upperThresholdSpin_->blockSignals(false);

    //reset doubleslider
    doubleSlider_->setMinimalAllowedSliderDistance(1.f / static_cast<float>(maximumIntensity_));
    doubleSlider_->blockSignals(true);
    doubleSlider_->setValues(0.f, 1.f);
    doubleSlider_->blockSignals(false);

    transferFuncIntensity_->setThresholds(0.f, 1.f);
    transferFuncGradient_->setThresholds(0.f, 1.f);

    applyThreshold();
}
void TransFuncEditorIntensityRamp::lowerThresholdSpinChanged(int value) {
    if (value+1 < maximumIntensity_) {
        //increment maximum of lower spin when maximum was reached and we are below upper range
        if (value == lowerThresholdSpin_->maximum())
            lowerThresholdSpin_->setMaximum(value+1);

        //update minimum of upper spin
        upperThresholdSpin_->blockSignals(true);
        upperThresholdSpin_->setMinimum(value);
        upperThresholdSpin_->blockSignals(false);
    }
    //increment value of upper spin when it equals value of lower spin
    if (value == upperThresholdSpin_->value()) {
        upperThresholdSpin_->blockSignals(true);
        upperThresholdSpin_->setValue(value+1);
        upperThresholdSpin_->blockSignals(false);
    }

    //update doubleSlider to new minValue
    doubleSlider_->blockSignals(true);
    doubleSlider_->setMinValue(value / static_cast<float>(maximumIntensity_));
    doubleSlider_->blockSignals(false);

    //apply threshold to transfer function
    applyThreshold();
}
Ejemplo n.º 6
0
cv::Mat LaneDetector::getLaneBinary(cv::Mat &image) {
    cv::Mat threshold_image(image.rows, image.cols, CV_8UC1, cvScalarAll(0));
    cv::Mat hough_image(image.rows, image.cols, CV_8UC1, cvScalarAll(0));
    threshold_image = applyThreshold(image, debug_mode);
    hough_image = applyHough(threshold_image, debug_mode);
    return hough_image;
} // Detect lanes and return a binary image with Lanes only
Ejemplo n.º 7
0
void Prewitt::save(int threshold){
    if(threshold == 0){
        cv::imwrite(getName(PREFIX, name, threshold), imagePrewitt);
    }else{
        cv::Mat img = applyThreshold(threshold);
        cv::imwrite(getName(PREFIX, name, threshold), img);
    }
}
Ejemplo n.º 8
0
cv::Mat MorphoFeatures::getEdges(const cv::Mat& image)
{
	cv::Mat result;
	// Take a gradient
	cv::morphologyEx(image, result, cv::MORPH_GRADIENT, cv::Mat());
	// Apply threshold to get binary image
	applyThreshold(result);
	return result;
}
Ejemplo n.º 9
0
BBFind::Rectangles BBFind::placePotentialBoxes(const Map3 fullMap)
{
   // Takes in a map of distances to edges and greedily places
   // a potential box at every local maximum. Because the distance
   // map is clipped, this should place numerous small boxes
   // inside the center of detected objects above the minimum size.
   // These boxes are later merged to form a single larger
   // bounding box for each object.

   int numCategories = fullMap.size();
	int mapWidth = fullMap[0][0].size();
	int mapHeight = fullMap[0].size();
	float val = 0.0f;
	float maxVal = 0.0f;
	Rectangles boundingBoxes(numCategories);

	const int stride = mBBGuessSize / 8;

   #ifdef PV_USE_OPENMP_THREADS
      #pragma omp parallel for
   #endif
   for(int c = 0; c < numCategories; c++)
   {
      Map2 distanceMap = applyThreshold(fullMap[c], mMinBlobSize);
      for(int y = 1; y < mapHeight-1; y+=stride)
		{
         for(int x = 1; x < mapWidth-1; x+=stride)
         {
				//Look at neighboring values to deduce if this is a local maximum
				maxVal = distanceMap[y][x];
				for(int i = -1; i <= 1; i++)
				{
					for(int j = -1; j <= 1; j++)
					{
						val = distanceMap[y+j][x+i];
						maxVal = val > maxVal ? val : maxVal;
					}
				}
				//If this was a local maximum, place a potential bounding box
				if(maxVal > 0 && maxVal == distanceMap[y][x])
				{
					boundingBoxes[c].push_back({x, y, mBBGuessSize, mBBGuessSize});
				}
			}
		}
	}

	return boundingBoxes;
}
Ejemplo n.º 10
0
void TransFunc1DRampEditor::thresholdChanged(float min, float max) {
    //convert to integer values
    int val_min = tgt::iround(min * maximumIntensity_);
    int val_max = tgt::iround(max * maximumIntensity_);

    //sync with spinboxes
    if ((val_max != upperThresholdSpin_->value()))
        upperThresholdSpin_->setValue(val_max);

    if ((val_min != lowerThresholdSpin_->value()))
        lowerThresholdSpin_->setValue(val_min);

    //apply threshold to transfer function
    applyThreshold();
}
Ejemplo n.º 11
0
void HSVDetector::findObjectAndServePosition() {

    // If we are able to get a an image
    if (image_source.getSharedMat(hsv_image)) {

        addWorldReferenceFrame();
        cv::cvtColor(hsv_image, hsv_image, cv::COLOR_BGR2HSV);
        applyThreshold();
        clarifyBlobs();
        siftBlobs();
        tune();

        position_sink.pushObject(object_position);
    }
}
void TransFuncEditorIntensityPet::restoreThresholds() {
    tgt::vec2 thresh = transferFuncIntensity_->getThresholds();
    resetThresholds();

    // update spinboxes
    int min = tgt::iround(thresh.x * (currentRange_.y - currentRange_.x) + currentRange_.x);
    int max = tgt::iround(thresh.y * (currentRange_.y - currentRange_.x) + currentRange_.x);

    lowerThresholdSpin_->blockSignals(true);
    lowerThresholdSpin_->setValue(min);
    lowerThresholdSpin_->blockSignals(false);
    upperThresholdSpin_->blockSignals(true);
    upperThresholdSpin_->setValue(max);
    upperThresholdSpin_->blockSignals(false);
    if (min + 1 < currentRange_.y) {
        //increment maximum of lower spin when maximum was reached and we are below upper range
        if (min == lowerThresholdSpin_->maximum())
            lowerThresholdSpin_->setMaximum(min + 1);

        //update minimum of upper spin
        upperThresholdSpin_->blockSignals(true);
        upperThresholdSpin_->setMinimum(min);
        upperThresholdSpin_->blockSignals(false);
    }

    if (max - 1 > currentRange_.x) {
        //increment minimum of upper spin when minimum was reached and we are above lower range
        if (max == upperThresholdSpin_->minimum())
            upperThresholdSpin_->setMinimum(max - 1);

        //update maximum of lower spin
        lowerThresholdSpin_->blockSignals(true);
        lowerThresholdSpin_->setMaximum(max);
        lowerThresholdSpin_->blockSignals(false);
    }

    transferFuncIntensity_->setThresholds(0.f, 1.f);
    transferFuncGradient_->setThresholds(0.f, 1.f);

    applyThreshold();

    // update doubleSlider
    doubleSlider_->blockSignals(true);
    doubleSlider_->setValues(oldThreshold_.x, oldThreshold_.y);
    doubleSlider_->setMinimalAllowedSliderDistance(1.f / static_cast<float>(currentRange_.y - currentRange_.x));
    doubleSlider_->blockSignals(false);
}
Ejemplo n.º 13
0
void threshold(int input_image[N][N],
               int threshold,
               int output_image[N][N])
    {
    int c;
    int r;
    int aux;
    for (r = 0; r < N; r++)
        {
    for (c = 0; c < N; c++)
        {
    aux = applyThreshold(input_image[r][c], threshold);
    output_image[r][c] = aux;
    }
    }
    return;
    }
void TransFuncEditorIntensityPet::sliderChanged(float min, float max) {
    //consider expand factor
    min = min * (currentRange_.y - currentRange_.x) + currentRange_.x;
    max = max * (currentRange_.y - currentRange_.x) + currentRange_.x;

    //sync with spinboxes
    int val = tgt::iround(max);
    if ((val != upperThresholdSpin_->value()))
        upperThresholdSpin_->setValue(val);

    val = tgt::iround(min);
    if ((val != lowerThresholdSpin_->value()))
        lowerThresholdSpin_->setValue(val);

    //apply threshold to both transfer functions
    applyThreshold();
    updateTransferFunction();
}
Ejemplo n.º 15
0
cv::Mat MorphoFeatures::getCorners(const cv::Mat& image)
{
	cv::Mat result;
	// Algorithm
	// Dilate with cross
	cv::dilate(image, result, cross);
	// Erode with a diamond
	cv::erode(result, result, diamond);
	// Another result image
	cv::Mat result2;
	// Dilate with x
	cv::dilate(image, result2, x);
	// Erode with square
	cv::erode(result2, result2, square);
	// Corners are calculated as absdiff between result and result2
	cv::absdiff(result2, result, result);
	// Apply threshold
	applyThreshold(result);
	return result;
}
void TransFuncEditorIntensityPet::volumeChanged() {
    if (volumeHandle_ && volumeHandle_->getRepresentation<Volume>()) {
        int bits = volumeHandle_->getRepresentation<Volume>()->getBitsStored() / volumeHandle_->getRepresentation<Volume>()->getNumChannels();
        int maxNew = static_cast<int>(pow(2.f, static_cast<float>(bits))) - 1;
        if (maxNew != maximumIntensity_) {
            maximumIntensity_ = maxNew;
            currentRange_ = tgt::ivec2(0, maximumIntensity_);

            lowerThresholdSpin_->blockSignals(true);
            upperThresholdSpin_->blockSignals(true);

            lowerThresholdSpin_->setRange(0, maximumIntensity_ - 1);
            lowerThresholdSpin_->setValue(tgt::iround(oldThreshold_.x * maximumIntensity_));

            upperThresholdSpin_->setRange(1, maximumIntensity_);
            upperThresholdSpin_->setValue(tgt::iround(oldThreshold_.y * maximumIntensity_));

            lowerThresholdSpin_->updateGeometry();
            upperThresholdSpin_->updateGeometry();

            lowerThresholdSpin_->blockSignals(false);
            upperThresholdSpin_->blockSignals(false);

            //set minimal distance of sliders in doubleSlider widget
            doubleSlider_->setMinimalAllowedSliderDistance(1.f / static_cast<float>(maximumIntensity_));
            doubleSlider_->blockSignals(true);
            doubleSlider_->setValues(oldThreshold_.x, oldThreshold_.y);
            doubleSlider_->blockSignals(false);

            applyThreshold();
        }
    }

    // propagate new volume to histogrampainter
    histogramPainter_->setHistogram(new HistogramIntensity((volumeHandle_ ? volumeHandle_->getRepresentation<Volume>() : 0), maximumIntensity_ + 1));
    // resize histogram painter
    histogramPainter_->setMinimumSize(200, 150);

    // clear old expand values
    ranges_.clear();
}
void TransFuncEditorIntensityPet::expandGradient() {
    //save old range
    ranges_.push_back(currentRange_);

    //new range of spinboxes
    currentRange_ = tgt::ivec2(lowerThresholdSpin_->value(), upperThresholdSpin_->value());

    //set minimum and maximum of thresholdspins
    lowerThresholdSpin_->setMinimum(lowerThresholdSpin_->value());
    lowerThresholdSpin_->setMaximum(upperThresholdSpin_->value() - 1);
    upperThresholdSpin_->setMinimum(lowerThresholdSpin_->value() + 1);
    upperThresholdSpin_->setMaximum(upperThresholdSpin_->value());

    //reset doubleslider
    doubleSlider_->blockSignals(true);
    doubleSlider_->setValues(0.f, 1.f);
    doubleSlider_->setMinimalAllowedSliderDistance(1.f / static_cast<float>(currentRange_.y - currentRange_.x));
    doubleSlider_->blockSignals(false);

    applyThreshold();
    updateTransferFunction();
}
void TransFuncEditorIntensityPet::collapseGradient() {
    if (ranges_.empty())
        return;

    //restore old range
    currentRange_ = ranges_[ranges_.size() - 1];
    ranges_.pop_back();

    //reset minimum and maximum values of spinboxes to values before last expand
    lowerThresholdSpin_->setMinimum(currentRange_.x);
    lowerThresholdSpin_->setMaximum(currentRange_.y - 1);
    upperThresholdSpin_->setMinimum(currentRange_.x + 1);
    upperThresholdSpin_->setMaximum(currentRange_.y);

    //reset double slider to range before last expand
    doubleSlider_->blockSignals(true);
    doubleSlider_->setMinimalAllowedSliderDistance(1.f / static_cast<float>(currentRange_.y - currentRange_.x));
    doubleSlider_->setValues((lowerThresholdSpin_->value() - currentRange_.x) / static_cast<float>(currentRange_.y - currentRange_.x),
                             (upperThresholdSpin_->value() - currentRange_.x) / static_cast<float>(currentRange_.y - currentRange_.x));
    doubleSlider_->blockSignals(false);

    applyThreshold();
    updateTransferFunction();
}
Ejemplo n.º 19
0
int main (int argc, char** argv)
{
	// for storing results of argument processing
	// general
	bool displayInfo = true;
	char* inFileName = "";

	// threshold filter
	bool runThreshold = false;
	float threshold = THRESH_ERROR;

	// crop
	bool runCrop = false;
	int cropWidth = CROP_DIM_ERROR;
	int cropHeight = CROP_DIM_ERROR;
	int cropStart[] = {0,0};

	// resize
	bool runResize = false;
	float scaling = SCALING_ERROR;
	char* resType = "";

	// default output file name
	char* outFileName = "out.bmp";
	
	// process arguments, checking for errors
	if (processArguments(argc, argv, &runThreshold, &runCrop, &runResize, 
		&displayInfo, &inFileName, &outFileName, &threshold, &cropWidth, 
		&cropHeight, cropStart, &scaling, &resType) != EXIT_SUCCESS)
	{
		fprintf(stderr, "Unable to process arguments.\n");
		return EXIT_FAILURE;
	}

	// open the file
	FILE *inFile = fopen(inFileName, "r");

	// check that file opened okay
	if (inFile == NULL)
	{
		fprintf(stderr, "Unable to open file: %s\n", inFileName);
		return EXIT_FAILURE;
	}

	// read in the file header and check that it went okay
	struct bmpFileHeader *fileHead = getFileHeader(inFile);

	if (fileHead == NULL)
	{
		fprintf(stderr, "Unable to set up file header.\n");
		return EXIT_FAILURE;
	}

	struct bmpInfoHeader *infoHead = getInfoHeader(inFile);

	if (infoHead == NULL)
	{
		fprintf(stderr, "Unable to set up info header.\n");
		return EXIT_FAILURE;
	}

	// check the format of the file
	if (formatCheck(fileHead, infoHead) != EXIT_SUCCESS)
	{
		fprintf(stderr, "Program cannot handle this format.\n");
		return EXIT_FAILURE;
	}


	// if we're displaying info, do so
	if (displayInfo)
	{
		// print out header information
		printInfo(fileHead, infoHead);
	}

	// move file pointer on to start of image, if necessary
	if (fileHead->offset != (sizeof(struct bmpFileHeader) + 
		sizeof(struct bmpInfoHeader)))
	{
		fseek(inFile, 
			((int)fileHead->offset - (sizeof(struct bmpFileHeader) + 
				sizeof(struct bmpInfoHeader))), SEEK_CUR);
	}

	// if we're running a threshold filter, do so
	if (runThreshold)
	{
		// apply threshold filter to image, checking for errors
		if (applyThreshold(inFile, fileHead, infoHead, outFileName, threshold) 
			== EXIT_FAILURE)
		{
			fprintf(stderr, "Unable to apply threshold.\n");
			return EXIT_FAILURE;
		}
	}

	// if we're cropping the image, do so
	if (runCrop)
	{
		// crop the image, checking for errors
		if (cropImage(inFile, fileHead, infoHead, outFileName, cropWidth,
			cropHeight, cropStart) == EXIT_FAILURE)
		{
			fprintf(stderr, "Unable to crop image.\n");
			return EXIT_FAILURE;
		}
	}

	// if we're resizing the image do so
	if (runResize)
	{
		// resize image checking for errors
		if (resizeImage(inFile, fileHead, infoHead, outFileName, scaling, resType) 
			== EXIT_FAILURE)
		{
			fprintf(stderr, "Unable to resize image.\n");
			return EXIT_FAILURE;
		}
	}

	// free up allocated memory
	free(infoHead);
	free(fileHead);

	// close input file, checking for errors
	if (fclose(inFile) != 0)
	{
		fprintf(stderr, "Unable to close input file.\n");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 20
0
void BBFind::detect()
{
   Map3 interpMap = getInterpolatedConfs(mFramesSinceNewMap++);

   int numCategories = interpMap.size();

   mCurrentConfMap.resize(numCategories);
   mDistMap.resize(numCategories);

   // Scale maps to our internal buffer size
   mCurrentConfMap = contrastAndAverage(
                        scale(interpMap, mInternalConfidenceWidth, mInternalConfidenceHeight, true),
                        mContrast,
                        mContrastStrength);

   // Apply light thresholding to remove noise
   for(int c = 0; c < numCategories; c++)
   {
      mCurrentConfMap[c] = applyThreshold(mCurrentConfMap[c], mThreshold / 3.0f);
   } 

   if(mPrevInfluence > 0)
   {
      mCurrentConfMap = sumMaps(mCurrentConfMap, mAccumulatedConfMap, mPrevInfluence);
      accumulateIntoPrev(mAccumulatedConfMap, mCurrentConfMap, mAccumulateAmount, mPrevLeakTau, -0.5f, 1.0f);
   }

   // Our values are all over the place right now,
   // so bring them back to 0 - 1 by alternating
   // a clip and squash, starting at a max of 3.5
   // and gradually reaching 1.0 over 8 iterations
   clipSquash(mCurrentConfMap, 8, 3.5f);

   // Apply our threshold and generate our distance map,
   // thresholded to the minimum blob size
   for(int c = 0; c < numCategories; c++)
   {
      mCurrentConfMap[c] = applyThreshold(mCurrentConfMap[c], mThreshold);
      mDistMap[c] = applyThreshold(
                        makeEdgeDistanceMap(
                           scale(mCurrentConfMap[c], mImageWidth, mImageHeight, true)
                           ),
                        mMinBlobSize);
   }

   // Clip our distance map so that regions
   // 2*minBlobSize pixels into an object are
   // saturated
   clip(mDistMap, 0.0f, mMinBlobSize * 2);

   // If mDetectionWait > 0, we wait a few frames
   // before generating bounding boxes. This allows us
   // to use previous frames for initial detections.
   if(mDetectionWaitTimer >= mDetectionWait)
   {
      // Detect potential boxes
      mDetections = placePotentialBoxes(mDistMap);
      // Join boxes that touch
      joinBoundingBoxes(mDetections);
      // Smooth box sizes with historical averages and join again
      smoothBoundingBoxes(mDetections);
      // Remove boxes that overlap by more than 75%
      competeBoundingBoxes(mDetections, 0.75f);
   }
   else mDetectionWaitTimer++;

   // Detection is finished. Use getDetections, getConfMap,
   // and getDistMap to retrieve the results.
}