MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / convertImageToDistanceMap

Function convertImageToDistanceMap

source/MRMesh/MRDistanceMap.cpp:237–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237Expected<MR::DistanceMap> convertImageToDistanceMap( const Image& image, float threshold, bool invert )
238{
239 threshold = std::clamp( threshold * 255, 0.f, 255.f );
240 DistanceMap dm( image.resolution.x, image.resolution.y );
241 const auto& pixels = image.pixels;
242 for ( int i = 0; i < image.pixels.size(); ++i )
243 {
244 const bool monochrome = pixels[i].r == pixels[i].g && pixels[i].g == pixels[i].b;
245 float value = float(pixels[i].r);
246 if ( !monochrome )
247 {
248 value = 0.299f * float( pixels[i].r ) +
249 0.587f * float( pixels[i].g ) +
250 0.114f * float( pixels[i].b );
251 }
252 if ( value < threshold )
253 continue;
254 dm.set( i, invert ? 255.0f - value : value );
255 }
256 return dm;
257}
258
259template <typename T = float>
260DistanceMap computeDistanceMap_( const MeshPart& mp, const MeshToDistanceMapParams& params, ProgressCallback cb,

Callers 2

loadDistanceMapFromImageFunction · 0.85
mainFunction · 0.85

Calls 3

clampFunction · 0.85
sizeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected