{"record":{"id":"f6b7edfb5b0d5774","repo":"Yalantis/uCrop","slug":"get-isoline3d-instance-is-not-a-scalar-image","errorCode":null,"errorMessage":"get_isoline3d(): Instance is not a scalar image.","messagePattern":"get_isoline3d\\(\\): Instance is not a scalar image\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":48346,"sourceCode":"                              (template type \\e tf should be at least \\e unsigned \\e int).\n       \\param isovalue The returned list of the 3D object colors.\n       \\param size_x The number of subdivisions along the X-axis.\n       \\param size_y The number of subdisivions along the Y-axis.\n       \\return The N vertices (xi,yi,zi) of the 3D object as a Nx3 CImg<float> image (0<=i<=N - 1).\n       \\par Example\n       \\code\n       const CImg<float> img(\"reference.jpg\");\n       CImgList<unsigned int> faces3d;\n       const CImg<float> points3d = img.get_isoline3d(faces3d,100);\n       CImg<unsigned char>().display_object3d(\"Isoline3d\",points3d,faces3d,colors3d);\n       \\endcode\n       \\image html ref_isoline3d.jpg\n    **/\n    template<typename tf>\n    CImg<floatT> get_isoline3d(CImgList<tf>& primitives, const float isovalue,\n                               const int size_x=-100, const int size_y=-100) const {\n      if (_spectrum>1)\n        throw CImgInstanceException(_cimg_instance\n                                    \"get_isoline3d(): Instance is not a scalar image.\",\n                                    cimg_instance);\n      if (_depth>1)\n        throw CImgInstanceException(_cimg_instance\n                                    \"get_isoline3d(): Instance is not a 2D image.\",\n                                    cimg_instance);\n      primitives.assign();\n      if (is_empty()) return *this;\n      CImg<floatT> vertices;\n      if ((size_x==-100 && size_y==-100) || (size_x==width() && size_y==height())) {\n        const _functor2d_int func(*this);\n        vertices = isoline3d(primitives,func,isovalue,0,0,width() - 1.f,height() - 1.f,width(),height());\n      } else {\n        const _functor2d_float func(*this);\n        vertices = isoline3d(primitives,func,isovalue,0,0,width() - 1.f,height() - 1.f,size_x,size_y);\n      }\n      return vertices;\n    }","sourceCodeStart":48328,"sourceCodeEnd":48364,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L48328-L48364","documentation":"CImg::get_isoline3d() extracts 3D isolines (contours at a given isovalue) from a scalar 2D image. The instance must have a single channel; CImg throws CImgInstanceException when _spectrum>1, i.e. the image is vector-valued (e.g. RGB or RGBA).","triggerScenarios":"Calling get_isoline3d directly on a color image loaded from file (spectrum 3 or 4), or on any multi-channel image, instead of a scalar (spectrum==1) image.","commonSituations":"Forgetting to convert an RGB height/intensity image to grayscale before contouring; applying isoline extraction to a feature stack image with several bands.","solutions":["Convert to scalar first: img.get_channel(0) or img.get_norm() / RGBtoYCbCr channel depending on intent.","Verify img._spectrum==1 before calling get_isoline3d.","If all channels are equal, take channel 0; if not, decide a reduction (luminance, mean, norm) and apply it.","Cache the scalar conversion once instead of converting per isoline call.","Wrap in try/catch on CImgInstanceException."],"exampleFix":"// before\nCImg<unsigned char> img = load(\"map.png\"); // RGBA, _spectrum==4\nimg.get_isoline3d(prims, 128.0f); // throws\n// after\nCImg<float> gray = img.get_channel(0).get_resize(...,-100,-100,1,1); // scalar\ngray.get_isoline3d(prims, 128.0f); // OK","handlingStrategy":"validation","validationCode":"if (img._spectrum>1)\n  img = img.get_channel(0); // or luminance/norm reduction\nimg.get_isoline3d(prims, isovalue);","typeGuard":"template<typename T>\nconst CImg<T>& require_scalar(const CImg<T>& img) {\n  if (img._spectrum>1) throw std::invalid_argument(\"expected scalar image\");\n  return img;\n}","tryCatchPattern":"try {\n  img.get_isoline3d(prims, isovalue);\n} catch (CImgInstanceException& e) {\n  std::fprintf(stderr, \"isoline3d needs a scalar 2D image: %s\\n\", e.what());\n}","preventionTips":["Convert RGB(A) inputs to grayscale/one channel at load time","Decide an explicit channel reduction (channel 0, luminance, norm)","Assert _spectrum==1 before contouring","Keep contouring input images separate from display textures"],"tags":["cimg","isoline","image-channels"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}