int ImageHandler::WriteImagesToFile() { Mat img1; stringstream ss; stringstream dd; string name = "IMG_"; string type = ".jpg"; for(int i=0; i<=img.rows-nSize; i++) { for(int j=0; j<=img.cols-nSize; j++) { Mat subImage(img, cv::Rect(j,i,nSize,nSize)); //subImages.push_back(subImage); ss<<dirs[0]<<"/IMG_"<<i<<"_"<<j<<type; string img_filename = ss.str(); imwrite(img_filename,subImage); //WriteImageMatrixToFile(img,dirs[1],i,j); ss.str(""); } } //cout<<subImages.size()<<endl; return 0; }
Descriptor TrueClusterHistogram::createHistogram(MyImage *image, size_t x_start, size_t width, size_t y_start, size_t height){ typedef Descriptor::iterator descit; Descriptor histogram(ncenters); bool first = true; // sliding window over the image for(int x = x_start; x + patch_size < width; x += spacing) for(int y = y_start; y + patch_size < height; y += spacing){ patch current_descriptor; { // get patch descriptor Magick::Image newim = *image->getMagickImage(); newim.crop(Magick::Geometry(patch_size, patch_size, x, y)); MyImage subImage(newim); Parameters::push(parameters); current_descriptor = feature->extract(&subImage); Parameters::pop(); } // change histogram according to descriptor and centers addToHistogram(current_descriptor, histogram, first); first = false; } return histogram; }
void ImageHandler::saveSubImages(vector<vector<int>>& subImages) { for(int i=0; i<=img.rows-nSize; i++) { for(int j=0; j<=img.cols-nSize; j++) { Mat subImage(img, cv::Rect(j,i,nSize,nSize)); vector<int> array; for(int k=0; k<subImage.rows; k++) { for(int l=0; l<subImage.cols; l++) { array.push_back(*(subImage.data + subImage.step[0]*k + subImage.step[1]*l)); } } //cout<<"1D vector: "<<name.str()<<" merete: "<<array.size()<<endl; subImages.push_back(array); array.clear(); } } }
void ImageHandler::saveSubImages(map<string,vector<int>>& subImages) { stringstream name; string name1; Mat subImage1; for(int i=0; i<=img.rows-nSize; i++) { for(int j=0; j<=img.cols-nSize; j++) { name<<"VEC_"<<i<<"_"<<j; Mat subImage(img, cv::Rect(j,i,nSize,nSize)); vector<int> array; for(int k=0; k<subImage.rows; k++) { for(int l=0; l<subImage.cols; l++) { array.push_back(*(subImage.data + subImage.step[0]*k + subImage.step[1]*l)); } } //cout<<"1D vector: "<<name.str()<<" merete: "<<array.size()<<endl; subImages[name.str()] = array; subImage.release(); name.str(""); } } }
MyImage TrueClusterHistogram::randomPatchImage(MyImage *image){ int x = rand() % (image->get_width() - patch_size); int y = rand() % (image->get_height() - patch_size); Magick::Image newim = *image->getMagickImage(); newim.crop(Magick::Geometry(patch_size, patch_size, x, y)); stringstream delme; MyImage subImage(newim); return subImage; }
int FrameLoader::getFrame(int frameNumber, IplImage **dst, _frame_normalization_methodT fnm, double normTarget) { _TICTOC_TIC_FUNC; message ("getFrame called ", verb_debug); if (lastFrameLoaded != frameNumber) { if (loadWholeFrame(frameNumber) != 0){ _TICTOC_TOC_FUNC; return -1; }; message ("loadWholeFrame returned ", verb_debug); lastFrameLoaded = frameNumber; } if (loadIm == NULL) { stringstream s("failed to load frame "); s << frameNumber << "\n"; message (s.str().c_str(), verb_error); _TICTOC_TOC_FUNC; return -1; } checkAr(); allocateImage(&convertedIm, loadIm); if (fnm == _frame_none) { message ("calling cloneImage ", verb_debug); cloneImage(loadIm, &convertedIm); } else { if (normTarget <= 0) { message("You asked me to normalize an image, but gave me a target <= 0", verb_warning); cloneImage(loadIm, &convertedIm); } else { double nf = getFrameNormFactor(frameNumber, fnm); if (nf > 0) { stringstream s; s << ("scaling frame: target norm factor = "); s << normTarget << " and this frame has nf: " << nf; nf = normTarget / nf; s << " so I am multiplying by " << nf << "\n"; cvConvertScale(loadIm, convertedIm, nf, 0); message(s.str().c_str(), verb_verbose); } else { message("Norm factor returned a value <= 0", verb_warning); cloneImage(loadIm, &convertedIm); } } } message ("calling subImage", verb_debug); string msg = "convertedIm info: " + imStrInfo(convertedIm); message (msg.c_str(), verb_debug); msg = "dst info: " + imStrInfo(*dst); message (msg.c_str(), verb_debug); subImage (convertedIm, dst, ar); _TICTOC_TOC_FUNC; message ("getFrame exiting", verb_debug); return 0; }
nsresult imgFrame::Extract(const nsIntRect& aRegion, imgFrame** aResult) { nsAutoPtr<imgFrame> subImage(new imgFrame()); if (!subImage) return NS_ERROR_OUT_OF_MEMORY; // The scaling problems described in bug 468496 are especially // likely to be visible for the sub-image, as at present the only // user is the border-image code and border-images tend to get // stretched a lot. At the same time, the performance concerns // that prevent us from just using Cairo's fallback scaler when // accelerated graphics won't cut it are less relevant to such // images, since they also tend to be small. Thus, we forcibly // disable the use of anything other than a client-side image // surface for the sub-image; this ensures that the correct // (albeit slower) Cairo fallback scaler will be used. subImage->mNeverUseDeviceSurface = PR_TRUE; nsresult rv = subImage->Init(0, 0, aRegion.width, aRegion.height, mFormat, mPaletteDepth); NS_ENSURE_SUCCESS(rv, rv); // scope to destroy ctx { gfxContext ctx(subImage->ThebesSurface()); ctx.SetOperator(gfxContext::OPERATOR_SOURCE); if (mSinglePixel) { ctx.SetDeviceColor(mSinglePixelColor); } else { // SetSource() places point (0,0) of its first argument at // the coordinages given by its second argument. We want // (x,y) of the image to be (0,0) of source space, so we // put (0,0) of the image at (-x,-y). ctx.SetSource(this->ThebesSurface(), gfxPoint(-aRegion.x, -aRegion.y)); } ctx.Rectangle(gfxRect(0, 0, aRegion.width, aRegion.height)); ctx.Fill(); } nsIntRect filled(0, 0, aRegion.width, aRegion.height); rv = subImage->ImageUpdated(filled); NS_ENSURE_SUCCESS(rv, rv); subImage->Optimize(); *aResult = subImage.forget(); return NS_OK; }
void ImageHandler::saveSubImages(vector<Mat> & subImages) { for(int i=0; i<=img.rows-nSize; i++) { for(int j=0; j<=img.cols-nSize; j++) { Mat subImage(img, cv::Rect(i,j,nSize,nSize)); subImages.push_back(subImage); subImage.release(); } } }
void ImageHandler::saveSubImages(vector< vector<Mat> > & subImages) { vector<Mat> row; for(int i=0; i<=img.rows-nSize; i++) { for(int j=0; j<=img.cols-nSize; j++) { Mat subImage(img, cv::Rect(j,i,nSize,nSize)); row.push_back(subImage); } subImages.push_back(row); row.clear(); } }
casa::LatticeHistograms<T>* ImageHistogram<T>::_filterByChannels( const casa::ImageInterface<T> * image ){ casa::LatticeHistograms<T>* imageHistogram = NULL; if ( m_channelMin != ALL_CHANNELS && m_channelMax != ALL_CHANNELS ){ //Create a slicer from the image casa::CoordinateSystem cSys = image->coordinates(); if ( cSys.hasSpectralAxis() ){ //We use the preset spectral coordinate, if it //exists because images can be rotated when they //come into the viewer. CoordinateSystem does not //take rotation into account. int spectralIndex = m_specIndex; if ( spectralIndex == -1 ){ spectralIndex = cSys.findCoordinate(casa::Coordinate::SPECTRAL); } if ( spectralIndex >= 0 ){ casa::IPosition imShape = image->shape(); int shapeCount = imShape.nelements(); casa::IPosition startPos( shapeCount, 0); casa::IPosition endPos(imShape - 1); casa::IPosition stride( shapeCount, 1); int endIndex = m_channelMax; if ( m_channelMax >= imShape(spectralIndex) && m_channelMin < imShape(spectralIndex)){ endIndex = imShape(spectralIndex) - 1; } startPos[spectralIndex] = m_channelMin; endPos[spectralIndex] = endIndex; casa::Slicer channelSlicer( startPos, endPos, stride, casa::Slicer::endIsLast ); casa::SubImage<T> subImage(*image, channelSlicer ); imageHistogram = new casa::LatticeHistograms<T>( subImage ); } } } else { imageHistogram = new casa::LatticeHistograms<T>(*image ); } return imageHistogram; }