void BitObject::drawOutline(Image<T_or_RGB>& img, const T_or_RGB& color, float opacity) { ASSERT(isValid()); ASSERT(img.initialized()); float op2 = 1.0F - opacity; Dims d = img.getDims(); Image<byte> mask = getObjectMask(); // rescale if needed if (d != itsImageDims) mask = rescaleNI(mask, d.w(), d.h()); // object-shaped drawing int thick = 1; Image<byte> om(mask); om = contour2D(om); // compute binary contour image const int w = img.getWidth(); const int h = img.getHeight(); Point2D<int> ppp; for (ppp.j = 0; ppp.j < h; ppp.j ++) for (ppp.i = 0; ppp.i < w; ppp.i ++) if (om.getVal(ppp.i, ppp.j)) // got a contour point -> draw here drawDisk(img, ppp, thick, T_or_RGB(img.getVal(ppp) * op2 + color * opacity)); // small disk for each point } // end drawOutline
Image<T> rescale(const Image<T>& src, const Dims& newdims, RescaleType ftype) { switch (ftype) { case RESCALE_SIMPLE_NOINTERP: return rescaleNI(src, newdims); case RESCALE_SIMPLE_BILINEAR: return rescaleBilinear(src, newdims); case RESCALE_FILTER_BOX : return genericRescale<BoxFilter>(src, newdims); case RESCALE_FILTER_TRIANGLE: return genericRescale<TriangleFilter>(src, newdims); case RESCALE_FILTER_BELL : return genericRescale<BellFilter>(src, newdims); case RESCALE_FILTER_BSPLINE : return genericRescale<BsplineFilter>(src, newdims); case RESCALE_FILTER_HERMITE : return genericRescale<HermiteFilter>(src, newdims); case RESCALE_FILTER_LANCZOS3: return genericRescale<Lanczos3Filter>(src, newdims); case RESCALE_FILTER_MITCHELL: return genericRescale<MitchellFilter>(src, newdims); default: LFATAL("invalid ftype '%c'", ftype); } ASSERT(0); return Image<T>(); }
void BitObject::drawShape(Image<T_or_RGB>& img, const T_or_RGB& color, float opacity) { ASSERT(isValid()); ASSERT(img.initialized()); Dims d = img.getDims(); Image<byte> mask = itsObjectMask; Rectangle bbox = itsBoundingBox; // rescale if needed if (d != itsImageDims) { float scaleW = (float) d.w() / (float) itsImageDims.w(); float scaleH = (float) d.h() / (float) itsImageDims.h(); int i = (int) ((float) bbox.left() * scaleW); int j = (int) ((float) bbox.top() * scaleH); int w = (int) ((float) bbox.width() * scaleW); int h = (int) ((float) bbox.height() *scaleH); const Point2D<int> topleft(i,j); bbox = Rectangle(topleft, Dims(w,h)); mask = rescaleNI(mask, d.w(), d.h()); } int w = img.getWidth(); float op2 = 1.0F - opacity; typename Image<T_or_RGB>::iterator iptr, iptr2; Image<byte>::const_iterator mptr = mask.begin(); iptr2 = img.beginw() + bbox.top() * w + bbox.left(); for (int y = bbox.top(); y <= bbox.bottomI(); ++y) { iptr = iptr2; for (int x = bbox.left(); x <= bbox.rightI(); ++x) { if (*mptr > 0) *iptr = T_or_RGB(*iptr * op2 + color * opacity); ++iptr; ++mptr; } iptr2 += w; } }
Image<T> rescaleOpt(const Image<T>& src, const int new_w, const int new_h, const bool interp) { if (interp) return rescaleBilinear(src, new_w, new_h); else return rescaleNI(src, new_w, new_h); }
Image<T> rescaleOpt(const Image<T>& src, const Dims& dims, const bool interp) { if (interp) return rescaleBilinear(src, dims); else return rescaleNI(src, dims); }
Image<T> rescaleNI(const Image<T>& src, const Dims& dims) { return rescaleNI(src, dims.w(), dims.h()); }