Roi Roi::subRoiAbs2Rel(const Roi& abs_sub_roi) const { if (!containsRoi(abs_sub_roi)) throw LIMA_COM_EXC(InvalidValue, "Given roi is not sub roi"); const Point& tl = getTopLeft(); return Roi(abs_sub_roi.getTopLeft() - tl, abs_sub_roi.getSize()); }
void CtImage::applyHard() { DEB_MEMBER_FUNCT(); if(m_img_type != m_next_image_type) { m_hw_det->setCurrImageType(m_next_image_type); m_img_type = m_next_image_type; } m_hw->apply(); //Add operation into internal header CtSaving* saving = m_ct.saving(); Bin bin;getBin(bin); if(!bin.isOne()) saving->addToInternalCommonHeader("binning",bin); Roi roi;getRoi(roi); if(!roi.isEmpty()) saving->addToInternalCommonHeader("roi",roi); Flip flip;getFlip(flip); if(flip.x || flip.y) saving->addToInternalCommonHeader("flip",flip); RotationMode rMode;getRotation(rMode); if(rMode != Rotation_0) saving->addToInternalCommonHeader("rotation",rMode); }
int Roi::overlapArea(Roi checkRoi){ int overlap = 0; // Calulate the intersection of the two roi overlap = max(0,min(lowerRightX, checkRoi.endX())-max(upperLeftX,checkRoi.startX())) * max(0,min(lowerRightY, checkRoi.endY())-max(upperLeftY,checkRoi.startY())); //overlap = max(0,min(upperLeftX, checkRoi.startX())-max(lowerRightX,checkRoi.endX())) * max(0,min(upperLeftY, checkRoi.startY())-max(lowerRightY,checkRoi.endY())); return overlap; }
Roi Roi::subRoiRel2Abs(const Roi& rel_sub_roi) const { Roi aux(0, getSize()); if (!aux.containsRoi(rel_sub_roi)) throw LIMA_COM_EXC(InvalidValue, "Given roi is not sub roi"); const Point& tl = getTopLeft(); return Roi(rel_sub_roi.getTopLeft() + tl, rel_sub_roi.getSize()); }
bool FilterROIs::check(const Roi& roi) const { bool passed = true; passed = passed && check_range(roi.w(), width_); passed = passed && check_range(roi.h(), height_); passed = passed && check_range(static_cast<double>(roi.w()) / roi.h(), aspect_); return passed; }
/***************************************************************//** * @brief Checks if Gauss peak centers are inside the MaxImageSize * *******************************************************************/ void FrameBuilder::checkPeaks( PeakList const &peaks ) { Size max_size; getMaxImageSize(max_size); Roi roi = Roi(0, max_size); vector<GaussPeak>::const_iterator p; for( p = peaks.begin( ); p != peaks.end( ); ++p ) { if( ! roi.containsPoint(Point(int(p->x0), int(p->y0))) ) throw LIMA_HW_EXC(InvalidValue, "Peak too far"); } }
void CtHwBinRoiFlip::setRoi(Roi& roi, bool round) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR2(roi,round); if (roi.isEmpty()) THROW_CTL_ERROR(InvalidValue) << "Hardware roi is empty"; if (!m_max_roi.containsRoi(roi)) THROW_CTL_ERROR(InvalidValue) << "Roi out of limts"; if (!m_has_roi) { if (!round) THROW_CTL_ERROR(NotSupported) << "No hardware roi available"; } else { Roi real_roi; m_hw_roi->checkRoi(roi, real_roi); if ((!round)&&(real_roi!=roi)) THROW_CTL_ERROR(InvalidValue) << "Given hardware roi not possible"; if (roi != m_set_roi) { m_hw_roi->setRoi(roi); m_set_roi= roi; _updateSize(); } roi= real_roi; } }
void RoiCtrlObj::checkEspiaRoi(const Roi& set_roi, Roi& hw_roi, Size& det_frame_size, Roi& espia_roi) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR2(set_roi, hw_roi); det_frame_size = hw_roi.getSize(); bool sg_roi = (!set_roi.isEmpty() && (hw_roi != set_roi)); if (sg_roi) { espia_roi = hw_roi.subRoiAbs2Rel(set_roi); int width = set_roi.getSize().getWidth(); bool horz_match = ((espia_roi.getTopLeft().x == 0) && (espia_roi.getSize().getWidth() == width)); sg_roi = (horz_match && ((width % 4) == 0)); } if (sg_roi) { DEB_TRACE() << "Horz. aligned roi qualifies for Espia SG!"; hw_roi = set_roi; } else espia_roi.reset(); DEB_RETURN() << DEB_VAR3(hw_roi, det_frame_size, espia_roi); }
void RoiCtrlObj::getRoi(Roi& hw_roi) { DEB_MEMBER_FUNCT(); m_cam.getRoi(hw_roi); Size det_frame_size; Roi espia_roi; m_acq.getSGRoi(det_frame_size, espia_roi); if (!espia_roi.isEmpty()) { if (det_frame_size != hw_roi.getSize()) THROW_HW_ERROR(Error) << "Camera/Espia roi mismatch: " << DEB_VAR2(det_frame_size, hw_roi); Roi final_hw_roi = hw_roi.subRoiRel2Abs(espia_roi); hw_roi = final_hw_roi; } DEB_RETURN() << DEB_VAR1(hw_roi); }
void CtSwBinRoiFlip::setRoi(const Roi& roi) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(roi); if (roi.isEmpty()) THROW_CTL_ERROR(InvalidValue) << "Software roi is empty"; if (!m_max_roi.containsRoi(roi)) THROW_CTL_ERROR(InvalidValue) << "Roi out of limts"; m_roi= roi; }
virtual void store(Setting& image_setting) { CtImage::ImageOpMode imageOpMode; m_image.getMode(imageOpMode); image_setting.set("imageOpMode",convert_2_string(imageOpMode)); // --- Roi Roi roi; m_image.getRoi(roi); Setting roi_setting = image_setting.addChild("roi"); const Point& topleft = roi.getTopLeft(); roi_setting.set("x",topleft.x); roi_setting.set("y",topleft.y); const Size& roiSize = roi.getSize(); roi_setting.set("width",roiSize.getWidth()); roi_setting.set("height",roiSize.getHeight()); // --- Bin Bin bin; m_image.getBin(bin); Setting bin_setting = image_setting.addChild("bin"); bin_setting.set("x",bin.getX()); bin_setting.set("y",bin.getY()); // --- Flip Flip flip; m_image.getFlip(flip); Setting flip_setting = image_setting.addChild("flip"); flip_setting.set("x",flip.x); flip_setting.set("y",flip.y); // --- Rotation RotationMode rMode; m_image.getRotation(rMode); image_setting.set("rotation",convert_2_string(rMode)); }
void CtImage::setRotation(RotationMode rotation) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(rotation); // Get previous roi unrotated RotationMode currentRotation; getRotation(currentRotation); Roi currentRoi; getRoi(currentRoi); Bin currentBin; getBin(currentBin); const Size& max_roi_size = m_hw->getMaxRoiSize(); currentRoi = currentRoi.getUnrotated(currentRotation,max_roi_size); m_sw->setRotation(rotation); resetRoi(); currentRoi = currentRoi.getRotated(rotation,max_roi_size); setRoi(currentRoi); }
void CtImage::setFlip(Flip &flip) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(flip); //Get previous roi unflipped Flip currentFlip; getFlip(currentFlip); Roi currentRoi; getRoi(currentRoi); RotationMode currentRotation; getRotation(currentRotation); const Size& max_roi_size = m_hw->getMaxRoiSize(); currentRoi = currentRoi.getUnrotated(currentRotation,max_roi_size); currentRoi = currentRoi.getFlipped(currentFlip,max_roi_size); if(!flip.x && ! flip.y) _resetFlip(); else { switch(m_mode) { case SoftOnly: m_sw->setFlip(flip); break; case HardOnly: m_hw->setFlip(flip,true); break; case HardAndSoft: _setHSFlip(flip); break; } } //Set the previous roi resetRoi(); currentRoi = currentRoi.getFlipped(flip,max_roi_size); currentRoi = currentRoi.getRotated(currentRotation,max_roi_size); setRoi(currentRoi); }
void CtImage::setRoi(Roi& roi) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(roi); if (roi.isEmpty()) { resetRoi(); return; } switch (m_mode) { case SoftOnly: m_sw->setRoi(roi); break; case HardOnly: { const Size& max_roi_size = m_hw->getMaxRoiSize(); // Remove the software Rotation to hardware Roi RotationMode aSoftwareRotation = m_sw->getRotation(); roi = roi.getUnrotated(aSoftwareRotation,max_roi_size); // Remove the software Flip to hardware Roi const Flip &aSoftwareFlip = m_sw->getFlip(); roi = roi.getFlipped(aSoftwareFlip,max_roi_size); m_hw->setRoi(roi, false); // Add Flip roi = roi.getFlipped(aSoftwareFlip,max_roi_size); // Add Rotation roi = roi.getRotated(aSoftwareRotation,max_roi_size); } break; case HardAndSoft: _setHSRoi(roi); break; } }
void CtImage::_setHSRoi(const Roi &roi) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(roi); if (m_hw->hasRoiCapability()) { Roi roi_unbin, roi_by_hw, roi_set_hw, roi_by_sw; Bin bin_total, bin_by_hw, bin_by_sw; RotationMode aSoftwareRotation = m_sw->getRotation(); bin_by_hw= m_hw->getBin(); bin_by_sw= m_sw->getBin(); bin_total= bin_by_hw * bin_by_sw; DEB_TRACE() << DEB_VAR3(bin_by_hw, bin_by_sw, bin_total); roi_unbin= roi.getUnbinned(bin_total); roi_by_hw= roi_unbin.getBinned(bin_by_hw); const Size& max_roi_size = m_hw->getMaxRoiSize(); // Remove the rotation to hardware Roi roi_by_hw= roi_by_hw.getUnrotated(aSoftwareRotation,max_roi_size); // Remove the software Flip to hardware Roi const Flip &aSoftwareFlip = m_sw->getFlip(); roi_by_hw= roi_by_hw.getFlipped(aSoftwareFlip,max_roi_size); roi_set_hw= roi_by_hw; m_hw->setRoi(roi_set_hw, true); DEB_TRACE() << DEB_VAR2(roi_by_hw, roi_set_hw); if (roi_set_hw==roi_by_hw) { m_sw->resetRoi(); } else { // Apply software flip to hardware roi roi_set_hw = roi_set_hw.getFlipped(aSoftwareFlip,max_roi_size); //Apply software rotation to hardware roi roi_set_hw = roi_set_hw.getRotated(aSoftwareRotation,max_roi_size); roi_by_sw= roi_set_hw.subRoiAbs2Rel(roi_by_hw); roi_by_sw= roi_by_sw.getBinned(bin_by_sw); m_sw->setRoi(roi_by_sw); } } else { m_sw->setRoi(roi); } }
void LabeledImage::loadRois(string host) { // URL: host/image/id/rois rois.clear(); char url[host.length() + 19 + 10]; sprintf(url, "http://%s/image/%u/rois", host.c_str(), id); const char* roiJSON = curlGet(url).c_str(); // Parse ROIs Document document; if(document.Parse<0>(roiJSON).HasParseError() || !document.IsArray()) { fprintf(stderr, "Error Parsing ROI JSON"); return; } for(uint32_t i = 0; i < document.Size(); i++) { // Build an ROI Roi *roi = new Roi(); roi->loadFromDocument(document[i]); rois.push_back(roi); } }
void Camera::setRoi(const Roi& set_roi) { DEB_MEMBER_FUNCT(); DEB_PARAM() << DEB_VAR1(set_roi); try { Point topleft, size; Roi hw_roi; getRoi(hw_roi); if (hw_roi == set_roi) return; if (set_roi.isActive()) { // --- a real roi available hw_roi = set_roi; //- set the new roi values //- cmd format is : "set_roi,x0,y0,x1,y1" std::stringstream strRoi; strRoi << "set_roi" << "," << set_roi.getTopLeft().x << "," << set_roi.getTopLeft().y << "," << set_roi.getTopLeft().x + set_roi.getSize().getWidth() << "," << set_roi.getTopLeft().y + set_roi.getSize().getHeight(); { yat::MutexLock scoped_lock(m_lock_data); _sendCmdAndReceiveAnswer(strRoi.str()); } } } catch (yat::SocketException & ySe) { std::stringstream ssError; for (unsigned i = 0; i < ySe.errors.size(); i++) { ssError << ySe.errors[i].desc << std::endl; } THROW_HW_ERROR(Error) << ssError.str(); } catch (...) { THROW_HW_ERROR(Error) << "setRoi : Unknown Exception"; } }
void RoiCtrlObj::setRoi(const Roi& set_roi) { DEB_MEMBER_FUNCT(); ROIS::const_iterator i; if(set_roi.isActive()) { i = _getRoi(set_roi); if(i == m_possible_rois.end()) THROW_HW_ERROR(Error) << "Something weird happen"; } else i = --m_possible_rois.end(); // full_frame if(m_has_hardware_roi) m_cam.setRoi(i->first.pattern); m_current_roi = i->second; m_current_max_frequency = i->first.max_frequency; }
/***************************************************************//** * @brief Checks the consistency of FrameDim, Bin and RoI * * First checks if Binning is valid * Then checks if FrameDim is inside of the MaxImageSize * Finally checks if the RoI is consistent with the binned frame dim *******************************************************************/ void FrameBuilder::checkValid( const FrameDim &frame_dim, const Bin &bin, const Roi &roi ) throw(Exception) { Size max_size; getMaxImageSize( max_size ); Bin valid_bin = bin; checkBin(valid_bin); if (valid_bin != bin) throw LIMA_HW_EXC(InvalidValue, "Invalid bin"); if( (frame_dim.getSize().getWidth() > max_size.getWidth()) || (frame_dim.getSize().getHeight() > max_size.getHeight()) ) throw LIMA_HW_EXC(InvalidValue, "Frame size too big"); FrameDim bin_dim = frame_dim / bin; if( roi.getSize() != 0 ) { bin_dim.checkValidRoi(roi); } }
bool Roi::pinit(Roi R, float percent) { float t = 2*percent/100*R.height(); // twice the percent is the total range of the random number int max_twice_offset = (int) t; // truncate int ulxoffset = rand()%max_twice_offset - t/2; // allow both positive and negative offsets int ulyoffset = rand()%max_twice_offset - t/2; // allow both positive and negative offsets int lrxoffset = rand()%max_twice_offset - t/2; // allow both positive and negative offsets int lryoffset = rand()%max_twice_offset - t/2; // allow both positive and negative offsets upperLeftX = R.startX() + ulxoffset; upperLeftY = R.startY() + ulyoffset; lowerRightX = R.endX() + lrxoffset; lowerRightY = R.endY() + lryoffset; roiValue = R.label(); randomlyGenerated = true; return(true); }
/***************************************************************//** * @brief Returns the closest RoI supported by the "hardware" * * @param[out] roi Roi object reference *******************************************************************/ void FrameBuilder::checkRoi( Roi &roi ) const { roi.alignCornersTo(8, Ceil); }
//virtual method Sarry::MaximumLikelihood::AlgResult Sarry::MaximumLikelihood::applyAlgorithm( const std::vector<PerPulseInfo>& pulseInfo, const Doi& doi, const Roi& roic) const { std::size_t doiSize = doi.getSamples().size(); std::size_t roicSize = roic.getRoic().size(); std::clog << "Size of g vector: " << roicSize << std::endl; std::clog << "Size of d vector: " << doiSize << std::endl; std::clog << "Creating F. . ." << std::endl; MatchedMatrix f(pulseInfo, m_chirp, doi, roic); ublas::matrix<std::complex<data_type> > FhF(roicSize, roicSize); ublas::vector<std::complex<data_type> > Fhd(roicSize); std::size_t num_threads = std::max<std::size_t>(boost::thread::hardware_concurrency(), 1); //Because F and Fh are large, reduce their scope. { ublas::matrix<std::complex<data_type> > Fh(roicSize, doiSize); BOOST_AUTO(reporters, getThreadReporters(num_threads, roicSize, "Rows", "All rows completed")); divvyWork(boost::bind(&initFh, boost::ref(Fh), f, _1, _2, doiSize, _3), num_threads, roicSize, reporters); //Accessing herm(F) is cache inefficient -- ublas::vector<std::complex<data_type> > d(doiSize); boost::copy(doi.getSamples() | transformed(px::bind(&KN::data, arg1)), d.begin()); ublas::matrix<std::complex<data_type> > F = herm(F); std::clog << "Creating F^H * d. . ." << std::endl; reporters = getThreadReporters(num_threads, roicSize, "Rows", "All rows completed"); divvyWork(boost::bind(&multFhd, boost::ref(Fhd), boost::cref(Fh), boost::cref(d), _1, _2, _3), num_threads, roicSize, reporters); std::clog << "Creating F^H * F. . ." << std::endl; reporters = getThreadReporters(num_threads, roicSize * roicSize, "Elements", "All rows completed"); divvyWork(boost::bind(&multFhF, boost::ref(FhF), boost::cref(Fh), boost::cref(F), _1, _2, _3), num_threads, roicSize, reporters); } //Write some debug output in case the matrices need conditioning, etc. { std::ofstream outInfo("about.log"), outFhd("Fhd.bin", std::ios::binary), outFhF("FhF.bin", std::ios::binary); if(!outInfo.is_open() || !outFhd.is_open() || ! outFhF.is_open()) throw std::runtime_error("Cannot open files"); outInfo << "Size of Fhd.bin vector:\n" << Fhd.size() << std::endl << "Sizes of FhF.bin matrix:\n" << FhF.size1() << " rows x " << FhF.size2() << " columns."; outFhd.write(reinterpret_cast<const char*>(&Fhd.data()[0]), sizeof(ComplexVector::value_type) * Fhd.data().size()); outFhF.write(reinterpret_cast<const char*>(&FhF.data()[0]), sizeof(ComplexMatrix::value_type) * Fhd.data().size()); } //If only I knew how to thread this. . . std::clog << "Performing LU factorization of F^H * F. . ." << std::endl; ublas::lu_factorize(FhF); std::clog << "Performing LU back substitution of (F^H * F)^(-1). . .\n"; //Cast to const& required to avoid ambiguity. ublas::lu_substitute( static_cast<const ublas::matrix<std::complex<data_type> >&>(FhF), Fhd); const Roi::IdxPairList& gIdcs = roic.getRoiIndexEnvelope(); std::ptrdiff_t azVals = boost::distance(gIdcs); if(azVals == 0) throw std::invalid_argument("No rows shown in ROI index envelope"); std::ptrdiff_t elVals = gIdcs.front().second - gIdcs.front().first; std::vector<std::complex<data_type> > gVals(azVals * elVals, std::complex<data_type>(0,0)); std::clog << "Creating ROI from ROIC. . ." << std::endl; std::size_t az = 0; for(Roi::IdxPairList::const_iterator it = boost::begin(gIdcs), end = boost::end(gIdcs); it != end; ++it, ++az) { std::size_t el = 0; for(std::size_t geoIdx = it->first; geoIdx != it->second; ++geoIdx, ++el) { gVals[az * elVals + el] += Fhd(geoIdx); } } return std::make_pair(gVals, static_cast<std::size_t>(elVals)); }