{"record":{"id":"c05af9fd1a8400f3","repo":"Yalantis/uCrop","slug":"streamline-instance-is-not-a-2d-or-3d-vector-fi","errorCode":null,"errorMessage":"streamline(): Instance is not a 2D or 3D vector field.","messagePattern":"streamline\\(\\): Instance is not a 2D or 3D vector field\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":41277,"sourceCode":"       \\param c0 Starting image channel.\n       \\param c1 Ending image channel.\n    **/\n    CImg<T> get_channels(const int c0, const int c1) const {\n      return get_crop(0,0,0,c0,width() - 1,height() - 1,depth() - 1,c1);\n    }\n\n    //! Return specified range of image channels \\inplace.\n    CImg<T>& channels(const int c0, const int c1) {\n      return get_channels(c0,c1).move_to(*this);\n    }\n\n    //! Return stream line of a 2D or 3D vector field.\n    CImg<floatT> get_streamline(const float x, const float y, const float z,\n                                const float L=256, const float dl=0.1f,\n                                const unsigned int interpolation_type=2, const bool is_backward_tracking=false,\n                                const bool is_oriented_only=false) const {\n      if (_spectrum!=2 && _spectrum!=3)\n        throw CImgInstanceException(_cimg_instance\n                                    \"streamline(): Instance is not a 2D or 3D vector field.\",\n                                    cimg_instance);\n      if (_spectrum==2) {\n        if (is_oriented_only) {\n          typename CImg<T>::_functor4d_streamline2d_oriented func(*this);\n          return streamline(func,x,y,z,L,dl,interpolation_type,is_backward_tracking,true,\n                            0,0,0,_width - 1.f,_height - 1.f,0.f);\n        } else {\n          typename CImg<T>::_functor4d_streamline2d_directed func(*this);\n          return streamline(func,x,y,z,L,dl,interpolation_type,is_backward_tracking,false,\n                            0,0,0,_width - 1.f,_height - 1.f,0.f);\n        }\n      }\n      if (is_oriented_only) {\n        typename CImg<T>::_functor4d_streamline3d_oriented func(*this);\n        return streamline(func,x,y,z,L,dl,interpolation_type,is_backward_tracking,true,\n                          0,0,0,_width - 1.f,_height - 1.f,_depth - 1.f);\n      }","sourceCodeStart":41259,"sourceCodeEnd":41295,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L41259-L41295","documentation":"CImg<T>::get_streamline() requires the image instance to be a vector field whose spectrum (channel count) is 2 or 3. The constructor-level overload validates this immediately and throws CImgInstanceException when _spectrum is anything else (e.g. grayscale or 4-channel data).","triggerScenarios":"Calling get_streamline(x,y,z,...) on an image whose _spectrum != 2 and != 3, e.g. a grayscale image (1 channel) or an RGBA image (4 channels).","commonSituations":"Loading a scalar image (PNG/JPEG grayscale) and passing it directly to streamline() expecting it to be a velocity/flow field; an image with alpha channel making spectrum=4; forgetting to call channels() to extract the 2-3 flow components.","solutions":["Check the image spectrum before calling: if img.spectrum() is not 2 or 3, reshape the data into a vector field first.","Extract 2 or 3 channels with img.get_channel(0).append(img.get_channel(1),'c') (etc.) to build a proper vector field.","If the source image has an unwanted alpha channel, use img.channels(0,2) to keep only the vector components.","If the field is grayscale, it is not a vector field; construct one explicitly from your components (e.g. CImg<float>(w,h,1,2))."],"exampleFix":"// before\nCImg<float> field = gray_image;             // spectrum()==1\nCImg<float> line = field.get_streamline(10,10,0);\n// after\nif (field.spectrum() < 2) {\n  CImg<float> vf(field.width(), field.height(), field.depth(), 2);\n  vf.get_shared_channel(0) = field;\n  vf.get_shared_channel(1) = field;  // fill with real vx/vy data\n}\nCImg<float> line = vf.get_streamline(10,10,0);","handlingStrategy":"validation","validationCode":"if (img.spectrum() != 2 && img.spectrum() != 3)\n  throw std::invalid_argument(\"streamline needs a 2D/3D vector field; spectrum=\" + std::to_string(img.spectrum()));","typeGuard":"bool is_vector_field(const CImg<float>& img) { return img.spectrum() == 2 || img.spectrum() == 3; }","tryCatchPattern":"try { line = field.get_streamline(x, y, z); }\ncatch (CImgInstanceException& e) { /* rebuild vector field from components or skip */ }","preventionTips":["Assert spectrum()==2 || spectrum()==3 right after loading the field","Strip alpha channels (channels(0,2)) before flow analysis","Never pass scalar images directly as vector fields"],"tags":["cimg","image-processing","vector-field"],"backgroundTag":"invalid-argument-value","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"}