void
pcl::pcl_2d::convolution_2d::conv  (ImageType &output, ImageType &kernel, ImageType &input){
  int rows = input.size ();
  int cols = input[0].size ();
  int k_rows = kernel.size ();
  int k_cols = kernel[0].size ();

  /*default boundary option : zero padding*/
  output.resize (input.size ());
  for (int i = 0; i < rows; i++)
  {
    output[i].resize (cols);
    for (int j = 0; j < cols; j++)
    {
      output[i][j] = 0;
      for (int k = 0; k < k_rows; k++)
      {
        for (int l = 0; l < k_cols; l++)
        {
          if ((i + k - k_rows / 2) < 0 || (i + k - k_rows / 2) >= rows || (j + l - k_cols / 2) < 0 || (j + l - k_cols / 2) >= cols)
          {
            continue;
          }
          else
          {
            output[i][j] += kernel[k][l] * input[i + k - k_rows / 2][j + l - k_cols / 2];
          }
        }
      }
    }
  }
}
Beispiel #2
0
/*
Expand image function
Writen by: Jeremiah Berns
Dependincies, image.cpp, image.h
Discription: Will accept the shrunken image, the grow size of the image, and then
	     expand the image back to 256x256
*/
void expandImage(ImageType oldImage, ImageType& newImage, int growVal, string newImageName)
{
  //Variable decliration
    int rows, cols, Q, tempValue;
	

  //Variable setting
    oldImage.getImageInfo(rows, cols, Q);

    for(int i=0;i<rows;i++)
      {
	for(int j=0;j<cols;j++)
	  {
	  oldImage.getPixelVal(i,j, tempValue);
	  for(int k=0;k<growVal;k++)
	    {
	      for(int l=0;l<growVal;l++)
	        {
		newImage.setPixelVal(i*growVal+k,j*growVal+l,tempValue);
		}
	    }
	  }
      }

  writeImage(newImageName, newImage);
}
Beispiel #3
0
template <unsigned dim,typename T> void
itkPhilipsRECDataImageReader::applyCorrection(FloatImageType::PointType correctorigin,
                                              FloatImageType::DirectionType correctdirection)
{
    // To take care of dimensions 3 and 4,
    // we need new direction and point types.
    typedef itk::Image<T,dim> ImageType;
    typedef typename ImageType::DirectionType correctDirectionType;
    typedef typename ImageType::PointType correctPointType;


    correctDirectionType direction;
    direction.SetIdentity();
    for (unsigned int i=0; i<3; i++)
        for (unsigned int j=0; j<3; j++)
            direction[i][j] = correctdirection[i][j];
    correctPointType origin;
    origin.Fill(0.0);
    for (unsigned int i=0; i<3; i++)
        origin[i] = correctorigin[i];

    ImageType* img = (ImageType *) (data()->data());
    img->SetDirection(direction);
    img->SetOrigin(origin);
}
void testSkinRecogWithThreshold(const std::vector<double> &mean, const Matrix &cov, ImageType &image, std::string out){

    RGB white(255,255,255);
    RGB black(0,0,0);

    int height, width, levels;
    image.getImageInfo(height,width,levels);

    RGB val;
    std::vector<double> pc(2); // pure color

    double thR, thG;
    for(int row = 0; row < height; row++){
     for(int col = 0; col < width; col++){
       image.getPixelVal(row, col, val);

       pc[0] = val.r/float(val.r+val.g+val.b);
       pc[1] = val.g/float(val.r+val.g+val.b);

       thR = exp(-(cov[0][0] * pow((pc[0] - mean[0]),2) +  cov[0][1] * (pc[0]- mean[0])));
       thG = exp(-(cov[1][0] * (pc[1] - mean[1]) + cov[1][1] * pow((pc[1] - mean[1]),2)));

       if((thR >= .9 && thG >= 1.0 && thG < 1.2)
         || (thR <= .8 && thR >= .7 && thG > 1.1)){
         image.setPixelVal(row, col, white);
       }
       else{
         image.setPixelVal(row, col, black);
       }
      }
     } // end outer for loop

    writeImage(out.c_str(), image);
}
    void verifyImagePixels(const ImageType& image,
            ImageFunction expectedPixels) {
        auto width = image.getWidth();
        auto height = image.getHeight();

        verifyImagePixels(image, width, height, expectedPixels);
    }
    cl::NDRange getLocalWorkSize(const ImageType&,
            const ImageType& destinationImage) const override {
        auto width = destinationImage.getWidth();
        auto height = destinationImage.getHeight();

        return cl::NDRange(width / 2, height / 2);
    }
static SoXipDataImage *
createXipImageSingle(SoItkDataImage * xipItkImage, SbXipImage::DataType typeFlag,
		     int bitsPerComp, SbXipImage::ComponentLayoutType compLayout)
{
    typedef typename itk::Image<Type, nDims> ImageType;
    ImageType * itkImage = reinterpret_cast<ImageType *>(xipItkImage->getPointer());

    typename ImageType::RegionType region = itkImage->GetBufferedRegion();

    SbXipImageDimensions dimensions(1, 1, 1);

    for (unsigned int i = 0; i < nDims; ++ i)
    {
	dimensions[i] = region.GetSize()[i];
    }

    SbXipImage* image =
	new SbXipImage(dimensions, typeFlag, bitsPerComp,
		       itkImage->GetBufferPointer(), nComps,
		       SbXipImage::INTERLEAVED, compLayout,
		       xipItkImage->getModelMatrix());

    if (!image) return 0;

    SoXipDataImage * xipImage = new SoXipDataImage;
    xipImage->ref();
    xipImage->addRef(xipItkImage);
    xipImage->set(image);

    return xipImage;
}
Beispiel #8
0
void
pcl::pcl_2d::edge::ComputeDerivativeXCentral (ImageType &output, ImageType &input){
  ImageType kernel;
  kernel.resize (3);
  kernel[0].resize (1); kernel[1].resize (1); kernel[2].resize (1);
  kernel[0][0] = -1; kernel[1][0] = 0; kernel[2][0] = 1;
  conv_2d->convolve  (output, kernel, input);
}
Beispiel #9
0
void crop(ImageType& image)
{
    if(imageLoaded(image))
        {
                // initialize to -1 for input validation
                int ULr = -1, ULc = -1, LRr = -1, LRc = -1;
                int N, M, Q;
                int errorCode = 0;

                // get values
                image.getImageInfo(N,M,Q);

                // get inputs
                cout << "Enter the upper left corner's row: ";
                cin >> ULr;             

                cout << endl << "Enter the upper left corner's column: ";
                cin >> ULc;

                cout << endl << "Enter the lower right corner's row: ";
                cin >> LRr;

                cout << endl << "Enter the lower right corner's column: ";
                cin >> LRc;

                // check for errors
                if(ULr < 0 || ULc < 0 || LRr < 0 || LRc < 0)
                        errorCode = 1;
                        
                else if(ULr > N || LRr > N || ULc > M || LRc > M)
                        errorCode = 2;

                else if(ULr >= LRr || ULc >= LRc)
                        errorCode = 3;

                switch(errorCode)
                {
                        case 1:
                                cout << "ERROR: All inputs must be non-negative.";
                                break;
                        case 2:
                                cout << "ERROR: All crop boundaries must be within image boundaries.";
                                break;
                        case 3:
                                cout << "ERROR: All crop boundaries must be in the correct order.";
                                break;
                }
                
                // crop image if no error was found
                if(errorCode == 0)
                {
                        image.getSubImage(ULr, ULc, LRr, LRc, image);
                        cout << endl << endl << "Image has been cropped successfully.";
                }
        
                pressEnterToContinue();
        }
}               
Beispiel #10
0
void write_output (const VectorType& data,
                   const vector<vector<int> >& mask_indices,
                   ImageType& image) {
  for (size_t i = 0; i < mask_indices.size(); i++) {
    for (size_t dim = 0; dim < image.ndim(); dim++)
      image.index(dim) = mask_indices[i][dim];
    image.value() = data[i];
  }
}
bool GtPlusAccumulatorImageTriggerGadget::storeImage(const ISMRMRD::ImageHeader& imgHeader, const hoNDArray<ValueType>& img, const ISMRMRD::MetaContainer& attrib, ImageBufferType& buf)
{
    try
    {
        long long cha = attrib.as_long(GADGETRON_CHA, 0);

        size_t slc = imgHeader.slice;

        long long e2 = attrib.as_long(GADGETRON_E2, 0);

        size_t con = imgHeader.contrast;
        size_t phs = imgHeader.phase;
        size_t rep = imgHeader.repetition;
        size_t set = imgHeader.set;
        size_t ave = imgHeader.average;

        // create image
        ImageType* storedImage = new ImageType();
        GADGET_CHECK_RETURN_FALSE(storedImage!=NULL);

        storedImage->from_NDArray(img);
        storedImage->attrib_ = attrib;
        GADGET_CHECK_RETURN_FALSE(gtPlus_util_.setMetaAttributesFromImageHeaderISMRMRD(imgHeader, storedImage->attrib_));

        storedImage->attrib_.set(GADGETRON_PASS_IMMEDIATE, (long)0);
        buf(cha, slc, e2, con, phs, rep, set, ave) = storedImage;

        if ( pass_image_immediate_ )
        {
            Gadgetron::GadgetContainerMessage<ImageBufferType>* cm1 = new Gadgetron::GadgetContainerMessage<ImageBufferType>();

            ImageBufferType& imgBuf = *(cm1->getObjectPtr());

            std::vector<size_t> dim2D(num_of_dimensions_, 1);
            imgBuf.create(dim2D);

            imgBuf(0) = new ImageType();
            *imgBuf(0) = *storedImage;

            // set the pass_image flag, so next gadget knows
            imgBuf(0)->attrib_.set(GADGETRON_PASS_IMMEDIATE, (long)1);

            if (this->next()->putq(cm1) < 0) 
            {
                cm1->release();
                return false;
            }
        }
    }
    catch(...)
    {
        GERROR_STREAM("Error happens in GtPlusAccumulatorImageTriggerGadget::storeImage(const ISMRMRD::ImageHeader& imgHeader, const hoNDArray<ValueType>& img, const ISMRMRD::MetaContainer& attrib, ImageBufferType& buf) ... ");
        return false;
    }

    return true;
}
Beispiel #12
0
void
pcl::keypoint::hessianBlob (ImageType &output, ImageType &input, const float sigma, bool SCALED){
  /*creating the gaussian kernels*/
  ImageType kernel, cornerness;
  conv_2d.gaussianKernel  (5, sigma, kernel);

  /*scaling the image with differentiation scale*/
  ImageType smoothed_image;
  conv_2d.convolve  (smoothed_image, kernel, input);

  /*image derivatives*/
  ImageType I_x, I_y;
  edge_detection.ComputeDerivativeXCentral  (I_x, smoothed_image);
  edge_detection.ComputeDerivativeYCentral  (I_y, smoothed_image);

  /*second moment matrix*/
  ImageType I_xx, I_yy, I_xy;
  edge_detection.ComputeDerivativeXCentral  (I_xx, I_x);
  edge_detection.ComputeDerivativeYCentral  (I_xy, I_x);
  edge_detection.ComputeDerivativeYCentral  (I_yy, I_y);
  /*Determinant of Hessian*/
  const size_t height = input.size ();
  const size_t width = input[0].size ();
  float min = std::numeric_limits<float>::max();
  float max = std::numeric_limits<float>::min();
  cornerness.resize (height);
  for (size_t i = 0; i < height; i++)
  {
    cornerness[i].resize (width);
    for (size_t j = 0; j < width; j++)
    {
      cornerness[i][j] = sigma*sigma*(I_xx[i][j]+I_yy[i][j]-I_xy[i][j]*I_xy[i][j]);
      if(SCALED){
        if(cornerness[i][j]  < min)
          min = cornerness[i][j];
        if(cornerness[i][j] > max)
          max = cornerness[i][j];
      }
    }

    /*local maxima*/
    output.resize (height);
    output[0].resize (width);
    output[height-1].resize (width);
    for (size_t i = 1; i < height - 1; i++)
    {
      output[i].resize (width);
      for (size_t j = 1; j < width - 1; j++)
      {
        if(SCALED)
          output[i][j] = ((cornerness[i][j]-min)/(max-min));
        else
          output[i][j] = cornerness[i][j];
      }
    }
  }
}
Beispiel #13
0
static jobject newIntImage(JNIEnv* env, ImageType& image) {
	jclass cls = safeFindClassMacro(cls, "Lcom/intel/vpg/IntImage;")
	jmethodID clsCons = safeFindMethodMacro(clsCons, cls, "<init>", "(II)V")
	jobject jintImage = env->NewObject(cls, clsCons, image.getWidth(),
			image.getHeight());
	jfieldID dataField = env->GetFieldID(cls, "data", "[I");
	jintArray jdata = (jintArray) env->GetObjectField(jintImage, dataField);
	arrayCopyToJNIMacro(data, Int, jint, image.getData())
	return jintImage;
}
std::unique_ptr<Image<OpenCVColorType>> OpenCVImageDenoiser::denoise(const ImageType& image) const
{
	cv::Mat img(image.height(), image.width(), CV_8UC3);
	for (int i = 0; i < img.rows; ++i)
		for (int j = 0; j < img.cols; ++j)
			img.at<cv::Vec3b>(i, j) = image[{i, j}];
//	cv::cvtColor(img, img, CV_BGR2GRAY);
	cv::Mat res(img.rows, img.cols, CV_8UC3);
	cv::fastNlMeansDenoisingColored(img, res);
	return std::make_unique<OpenCVImage>(res);
}
void testSkinRecognition(const BayesianClassifier &classifier, ImageType &image, ImageType &ref, std::string out, bool YCbCr){

    int height, width, levels;
    image.getImageInfo(height,width,levels);
    ImageType outImg(height,width,levels);

    RGB val1, val2;
    int label;
    std::vector<double> color(2);
    int TP = 0, TN = 0, FN = 0, FP = 0;
    RGB white(255,255,255);
    RGB black(0,0,0);

    for(int row = 0; row < height; row++){
      for(int col = 0; col < width; col++){
        image.getPixelVal(row, col, val1);
        ref.getPixelVal(row, col, val2);

        if(YCbCr == true){
          color[0] = -0.169*val1.r - 0.332*val1.g+ 0.500*val1.b;
          color[1] = 0.500*val1.r - 0.419*val1.g - 0.081*val1.b;
        }
        else{
          color[0] = val1.r/float(val1.r+val1.g+val1.b);
          color[1] = val1.g/float(val1.r+val1.g+val1.b);
        }

        label = classifier.predict(color);

        if(label == 0){
          outImg.setPixelVal(row, col, white);
          if(val2 != black){ TP++; } else{ FP++; }
        }
        else{
          outImg.setPixelVal(row, col, black);
          if(val2 == black){ TN++; } else{ FN++; }
        }
      }
    }  // end outer for loop

    std::cout << std::endl
              << "TP: " << TP << std::endl
              << "TN: " << TN << std::endl
              << "FP: " << FP << std::endl
              << "FN: " << FN << std::endl;

    /*std::stringstream ss;
    ss << FP << " " << FN;
    Debugger debugger("Data_Prog2/errors3a.txt",true);
    debugger.debug(ss.str());
    */

    writeImage(out.c_str(), outImg);
}
Beispiel #16
0
void getMLEParameters(ImageType& trainingImage, ImageType& refImage, bool useRGB, Vector2f &estSkinMu, Matrix2f &estSkinSigma, Vector2f &estNonSkinMu, Matrix2f &estNonSkinSigma)
{
	vector<Vector2f> sampleSkinData, sampleNonSkinData;

	RGB val;

 	float total, x1, x2;
 	total = x1 = x2 = 0;

	for(int i=0; i<N; i++)
	{
		for(int j=0; j<M; j++) 
		{
			trainingImage.getPixelVal(i, j, val);
			if(useRGB)
			{
				total = val.r + val.g + val.b;
				if(total == 0)
				{
					x1 = x2 = 0;
				}
				else
				{
					x1 = (float)val.r / total;	//New Red value
					x2 = (float)val.g / total;  //New Green Value	
				}
			}
			else
			{
				x1 = -0.169 * (float)val.r - 0.332 * (float)val.g + 0.5 * (float)val.b; //New Cb value
				x2 = 0.5 * (float)val.r - 0.419 * (float)val.g - 0.081 * (float)val.b;  //New Cr value
			}
			refImage.getPixelVal(i, j, val);
			if(val.r != 0 && val.g != 0 && val.b != 0)
			{
				sampleSkinData.push_back(Vector2f(x1, x2));
			}
			else
			{
				// cout << x1 << "\t" << x2 << endl;
				sampleNonSkinData.push_back(Vector2f(x1, x2));
			}
		}
	}


	estNonSkinMu = MLE::calculateSampleMean(sampleNonSkinData);
	estNonSkinSigma = MLE::calculateSampleCovariance(sampleNonSkinData, estNonSkinMu);
	estSkinMu = MLE::calculateSampleMean(sampleSkinData);
	estSkinSigma = MLE::calculateSampleCovariance(sampleSkinData, estSkinMu);
	
}
Beispiel #17
0
float otsu_threshold(const ImageType& src)
{
    std::pair<typename ImageType::value_type,typename ImageType::value_type>
    min_max = min_max_value(src.begin(),src.end());
    std::vector<unsigned int> hist;
    histogram(src,hist,min_max.first,min_max.second);
    if(hist.empty())
        return min_max.first;
    std::vector<unsigned int> w(hist.size());
    std::vector<float> sum(hist.size());
    w[0] = hist[0];
    sum[0] = 0.0;
    for (unsigned int index = 1,last_w = hist[0],last_sum = 0.0; index < hist.size(); ++index)
    {
        w[index] = last_w + hist[index];
        sum[index] = last_sum + hist[index]*index;
        last_w = w[index];
        last_sum = sum[index];
    }
    float total_sum = sum.back();
    float total_w = w.back();

    float max_sig_b = 0.0;
    unsigned int optimal_threshold = 0;

    for (unsigned int index = 0; index < hist.size()-1; ++index)
    {
        if (!w[index])
            continue;
        unsigned int w2 = (total_w-w[index]);
        if (!w2)
            continue;

        float d = sum[index]*(float)total_w;
        d -= total_sum*(float)w[index];
        d *= d;
        d /= w[index];
        d /= w2;
        if (d > max_sig_b)
        {
            max_sig_b = d;
            optimal_threshold = index;
        }
    }
    float optimal_threshold_value = optimal_threshold;
    optimal_threshold_value /= hist.size();
    optimal_threshold_value *= min_max.second - min_max.first;
    optimal_threshold_value += min_max.first;
    return optimal_threshold_value;
}
Beispiel #18
0
void
pcl::keypoint::imageElementMultiply (ImageType &output, ImageType &input1, ImageType &input2){
  const size_t height = input1.size ();
  const size_t width = input1[0].size ();
  output.resize (height);
  for (size_t i = 0; i < height; i++)
  {
    output[i].resize (width);
    for (size_t j = 0; j < width; j++)
    {
      output[i][j] = input1[i][j] * input2[i][j];
    }
  }
}
Beispiel #19
0
void
pcl::pcl_2d::edge::robertsXY  (ImageType &Gx, ImageType &Gy, ImageType &input)
{
  ImageType kernelX;
  kernelX.resize (2); kernelX[0].resize (2); kernelX[1].resize (2);
  kernelX[0][0] = 1; kernelX[0][1] = 0;
  kernelX[1][0] = 0; kernelX[1][1] = -1;
  conv_2d->convolve (Gx, kernelX, input);

  ImageType kernelY;
  kernelY.resize (2); kernelY[0].resize (2); kernelY[1].resize (2);
  kernelY[0][0] = 0; kernelY[0][1] = 1;
  kernelY[1][0] = -1; kernelY[1][1] = 0;
  conv_2d->convolve (Gy, kernelY, input);
}
Beispiel #20
0
/*
Histogram Equalization function
Written by: Jeremiah Berns
Dependincies:image.h, image.cpp
Discription:  This function will perform the histogram equalization algorithem to the oldImage
             and will output the newImage with the given newImageName.  
*/
void histogramEq(ImageType oldImage, ImageType& newImage, string newImageName)
{
  int rows, cols, Q, pixelValue, pixelCount;
  oldImage.getImageInfo(rows,cols,Q);
  pixelCount = rows*cols;
  int adjustedHistogram[Q];
  double histogramArray[Q], equalizedHistogram[Q];
  double probabilityArray[Q], cumulativeProbability[Q], probTotal=0;
 

  for (int i = 0; i<Q;i++)
    {
    histogramArray[i] = 0;
    equalizedHistogram[i] = 0;

    }

  for(int i=0; i<rows;i++)
    {
      for(int j=0; j<cols;j++)
        {
	  oldImage.getPixelVal(i,j,pixelValue);
  	  histogramArray[pixelValue]+=1;
	}
    }

  for(int i=0;i<Q;i++)
    {
     probTotal+= histogramArray[i]/pixelCount;
    
     cumulativeProbability[i] = probTotal;
     cumulativeProbability[i] = cumulativeProbability[i]*255;
     adjustedHistogram[i] = cumulativeProbability[i];
     cout<<adjustedHistogram[i]<<endl;
    }

  for(int i=0; i<rows;i++)
    {
      for(int j=0; j<cols;j++)
        {
	  oldImage.getPixelVal(i,j,pixelValue);
  	  newImage.setPixelVal(i,j,adjustedHistogram[pixelValue-1]);
	}
    }

  writeImage(newImageName, newImage);
}
void writeImage(const char fname[], ImageType& image)
/* write PPM image */
{
    int i, j;
    int N, M, Q;
    unsigned char *charImage;
    ofstream ofp;

    image.getImageInfo(N, M, Q);

    // make space for PPM
    charImage = (unsigned char *) new unsigned char [3*M*N];

    // convert the RGB  to unsigned char
    RGB val;
    for(i=0; i<N; i++) {
        for(j=0; j<3*M; j+=3) {
            image.getPixelVal(i, j/3, val);
            charImage[i*3*M+j]=(unsigned char)val.r;
            charImage[i*3*M+j+1]=(unsigned char)val.g;
            charImage[i*3*M+j+2]=(unsigned char)val.b;
        }
    }

    ofp.open(fname, ios::out | ios::binary);

    if (!ofp) {
        cout << "Can't open file: " << fname << endl;
        exit(1);
    }

    ofp << "P6" << endl;
    ofp << M << " " << N << endl;
    ofp << Q << endl;

    ofp.write( reinterpret_cast<char *>(charImage), (3*M*N)*sizeof(unsigned char));

    if (ofp.fail()) {
        cout << "Can't write image " << fname << endl;
        exit(0);
    }

    ofp.close();

    delete [] charImage;

}
Beispiel #22
0
void displayInfo(ImageType& image)
{
    if(imageLoaded(image))
        {
                int N, M, Q;
                
                // get values
                image.getImageInfo(N,M,Q);

                cout << "Height           : " << N << endl
                         << "Width            : " << M << endl
                         << "Max Pixel Value  : " << Q << endl
                         << "Mean Gray Value  : " << image.meanGray();

                pressEnterToContinue();
        }
}
Beispiel #23
0
void
pcl::pcl_2d::edge::robertsMagnitudeDirection  (ImageType &G, ImageType &thet, ImageType &input){
  ImageType Gx;
  ImageType Gy;
  robertsXY (Gx, Gy, input);
  G.resize (input.size ());
  thet.resize (input.size ());
  for (int i = 0; i < input.size (); i++)
  {
    G[i].resize (input[i].size ());
    thet[i].resize (input[i].size ());
    for (int j = 0; j < input[i].size (); j++)
    {
      G[i][j] = sqrt (Gx[i][j] * Gx[i][j] + Gy[i][j] * Gy[i][j]);
      thet[i][j] = atan2 (Gy[i][j], Gx[i][j]);
    }
  }
}
Beispiel #24
0
void
pcl::keypoint::hessianBlob (ImageType &output, ImageType &input, const float start_scale, const float scaling_factor, const int num_scales){
  const size_t height = input.size();
  const size_t width = input[0].size();
  const int local_search_radius = 1;
  float scale = start_scale;
  std::vector<ImageType> cornerness;
  cornerness.resize(num_scales);
  for(int i = 0;i < num_scales;i++){
    hessianBlob(cornerness[i], input, scale, false);
    scale *= scaling_factor;
  }
  bool non_max_flag = false;
  float scale_max, local_max;
  for(size_t i = 0;i < height;i++){
    for(size_t j = 0;j < width;j++){
      scale_max = std::numeric_limits<float>::min();
      /*default output in case of no blob at the current point is 0*/
      output[i][j] = 0;
      for(int k = 0;k < num_scales;k++){
        /*check if the current point (k,i,j) is a maximum in the defined search radius*/
        non_max_flag = false;
        local_max = cornerness[k][i][j];
        for(int n = -local_search_radius; n <= local_search_radius;n++){
          if(n+k < 0 || n+k >= num_scales)
            continue;
          for(int l = -local_search_radius;l <= local_search_radius;l++){
            if(l+i < 0 || l+i >= height)
              continue;
            for(int m = -local_search_radius; m <= local_search_radius;m++){
              if(m+j < 0 || m+j >= width)
                continue;
              if(cornerness[n+k][l+i][m+j] > local_max){
                non_max_flag = true;
                break;
              }
            }
            if(non_max_flag)
              break;
          }
          if(non_max_flag)
            break;
        }
        /*if the current point is a point of local maximum, check if it is a maximum point across scales*/
        if(!non_max_flag){
          if(cornerness[k][i][j] > scale_max){
            scale_max = cornerness[k][i][j];
            /*output indicates the scale at which the blob is found at the current location in the image*/
            output[i][i] = start_scale*pow(scaling_factor, k);
          }
        }
      }
    }
  }
}
Beispiel #25
0
//readimage Function
void readImage(string fname, ImageType& image){
	int i, j;
	int N, M, Q;
	unsigned char *charImage;
	char header [100], *ptr;
	ifstream ifp;
	ifp.open(fname.c_str(), ios::in | ios::binary);

	if (!ifp) {
		cout << "Can't read image: " << fname << endl;
		exit(1);
	}

	// read header

	ifp.getline(header,100,'\n');
	if((header[0]!=80) || (header[1]!=53) ) {
    	cout << "Image " << fname << " is not PGM" << endl;
    	exit(1);
	}

	ifp.getline(header,100,'\n');

	while(header[0]=='#')
	ifp.getline(header,100,'\n');


	M=strtol(header,&ptr,0);
	N=atoi(ptr);

	ifp.getline(header,100,'\n');

	Q=strtol(header,&ptr,0);

	cout<<Q<<endl;

	charImage = (unsigned char *) new unsigned char [M*N];

	ifp.read( reinterpret_cast<char *>(charImage), (M*N)*sizeof(unsigned char));

	if (ifp.fail()) {
		exit(1);
	}

	ifp.close();

	int val;

	for(i=0; i<N; i++) {
		for(j=0; j<M; j++) {
			val = (int)charImage[i*M+j];
			image.setPixelVal(i, j, val);     
   		}
   	}
}
Beispiel #26
0
/**
 * must release array data after the use of it
 */
static jintArray useImage(JNIEnv* env, jobject jimg, ImageType& img,
		jint** pdata) {
	int w = 0;
	int h = 0;

	jintArray jdata = intImageArray(env, jimg, &w, &h);
	*pdata = lockArray(data, Int);

	img.wrappingOf(*pdata, w, h);
	return jdata;
}
Beispiel #27
0
void writeImage(string fname, ImageType& image){
	int i, j;
	int N, M, Q;
	unsigned char *charImage;
	ofstream ofp;

	image.getImageInfo(N, M, Q);

	charImage = (unsigned char *) new unsigned char [M*N];

	// convert the integer values to unsigned char

	int val;

	for(i=0; i<N; i++){
		for(j=0; j<M; j++){
			image.getPixelVal(i, j, val);
			charImage[i*M+j]=(unsigned char)val;
		}
	}

	ofp.open(fname.c_str(), ios::out | ios::binary);

	if (!ofp) {
		cout << "Can't open file: " << fname << endl;
		exit(1);
	}

	ofp << "P5" << endl;
	ofp << M << " " << N << endl;
	ofp << Q << endl;

	ofp.write( reinterpret_cast<char *>(charImage), (M*N)*sizeof(unsigned char));

	if (ofp.fail()) {
		cout << "Can't write image " << fname << endl;
		exit(0);
	}

	ofp.close();
}
    void verifyImagePixels(const ImageType& image, unsigned int startX,
            unsigned int startY, unsigned int endX, unsigned int endY,
            ImageFunction expectedPixels) {
        for (auto x = startX; x < endX; ++x) {
            for (auto y = startY; y < endY; ++y) {
                auto pixelValue = image.getPixelValue(x, y);
                auto expectedPixelValue = expectedPixels(x, y);

                assertThat(pixelValue).isEqualTo(expectedPixelValue);
            }
        }
    }
Beispiel #29
0
void
pcl::pcl_2d::edge::cannyTraceEdge  (int rowOffset, int colOffset, int row, int col, float theta, float tLow, float tHigh, ImageType &G, ImageType &thet){
  int newRow = row + rowOffset;
  int newCol = col + colOffset;
  if (newRow > 0 && newRow < G.size () && newCol > 0 && newCol < G[0].size ())
  {
    if (G[newRow][newCol] < tLow || G[newRow][newCol] > tHigh || thet[newRow][newCol] != theta)
      return;
    G[newRow][newCol] = tHigh + 1;
    cannyTraceEdge  (rowOffset,colOffset, newRow, newCol, theta, tLow, tHigh, G, thet);
  }
}
void makeColorMatrices(ImageType& img, ImageType& ref, Matrix &sk_cols,
  Matrix &nsk_cols, bool YCbCr)
{
  int height1, width1, levels1;
  int height2, width2, levels2;
  img.getImageInfo(height1, width1, levels1);
  ref.getImageInfo(height2, width2, levels2);

  assert(height1 == height2);
  assert(width1 == width2);
  assert(levels1 == levels2);

  RGB val1, val2;
  std::vector<double> color(2);
  RGB black(0,0,0);

  for(int row = 0; row < height1; row++){
    for(int col = 0; col < width1; col++){
      img.getPixelVal(row, col, val1);
      ref.getPixelVal(row, col, val2);

      if(YCbCr == true){
        color[0] = -0.169*val1.r - 0.332*val1.g+ 0.500*val1.b;
        color[1] = 0.500*val1.r - 0.419*val1.g - 0.081*val1.b;
      }
      else{
        color[0] = val1.r/float(val1.r+val1.g+val1.b);
        color[1] = val1.g/float(val1.r+val1.g+val1.b);
      }

      if(val2 != black){
        sk_cols.push_back(color);
      }
      else{
        nsk_cols.push_back(color);
      }
    }
  }
}