Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
Image_Diff Class Reference

This class compares two images pixel-by-pixel. It uses the following methods to ignore the difference between images: More...

#include <Image_Diff.hxx>

Inheritance diagram for Image_Diff:
Inheritance graph
[legend]

Public Member Functions

 Image_Diff ()
 An empty constructor. Init() should be called for initialization.
 
 ~Image_Diff () override
 Destructor.
 
bool Init (const occ::handle< Image_PixMap > &theImageRef, const occ::handle< Image_PixMap > &theImageNew, const bool theToBlackWhite=false)
 Initialize algorithm by two images.
 
bool Init (const TCollection_AsciiString &theImgPathRef, const TCollection_AsciiString &theImgPathNew, const bool theToBlackWhite=false)
 Initialize algorithm by two images (will be loaded from files).
 
void SetColorTolerance (const double theTolerance)
 Color tolerance for equality check. Should be within range 0..1: Corresponds to a difference between white and black colors (maximum difference). By default, the tolerance is equal to 0 thus equality check will return false for any different colors.
 
double ColorTolerance () const
 Color tolerance for equality check.
 
void SetBorderFilterOn (const bool theToIgnore)
 Sets taking into account (ignoring) a "border effect" on comparison of images. The border effect is caused by a border of shaded shapes in the viewer 3d. Triangles of this area are located at about 0 or 90 degrees to the user. Therefore, they deflect light differently according to implementation of a video card driver. This flag allows to detect such a "border" area and skip it from comparison of images. Filter turned OFF by default.
 
bool IsBorderFilterOn () const
 Returns a flag of taking into account (ignoring) a border effect in comparison of images.
 
int Compare ()
 Compares two images. It returns a number of different pixels (or groups of pixels). It returns -1 if algorithm not initialized before.
 
bool SaveDiffImage (Image_PixMap &theDiffImage) const
 Saves a difference between two images as white pixels on black background.
 
bool SaveDiffImage (const TCollection_AsciiString &theDiffPath) const
 Saves a difference between two images as white pixels on black background.
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor.
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing.
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter.
 
virtual ~Standard_Transient ()=default
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
bool IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
bool IsInstance (const char *const theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
bool IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism.
 
bool IsKind (const char *const theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism.
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero.
 
int GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object. Uses relaxed memory ordering since incrementing only requires atomicity, not synchronization with other memory operations.
 
int DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value. Uses release ordering for the decrement to ensure all writes to the object are visible before the count reaches zero. An acquire fence is added only when the count reaches zero, ensuring proper synchronization before deletion. This is more efficient than using acq_rel for every decrement.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Protected Member Functions

int ignoreBorderEffect ()
 Perform border filter algorithm.
 
void releaseGroupsOfDiffPixels ()
 Release dynamically allocated memory.
 

Static Protected Member Functions

static int PackXY (uint16_t theX, uint16_t theY)
 Map two pixel coordinates to 32-bit integer.
 
static uint16_t UnpackX (int theXY)
 Get pixel X coordinate from 32-bit packed integer.
 
static uint16_t UnpackY (int theXY)
 Get pixel Y coordinate from 32-bit packed integer.
 

Protected Attributes

occ::handle< Image_PixMapmyImageRef
 reference image to compare (from)
 
occ::handle< Image_PixMapmyImageNew
 new image to compare (to)
 
double myColorTolerance
 tolerance for equality check (0..1, 0 - any not equal, 1 - opposite colors)
 
bool myIsBorderFilterOn
 perform algorithm with border effect filter
 
NCollection_DynamicArray< intmyDiffPixels
 coordinates of different pixels, packed in one int using 16-bit integers to save memory
 
TColStd_PackedMapOfInteger myLinearGroups
 
NCollection_List< occ::handle< TColStd_HPackedMapOfInteger > > myGroupsOfDiffPixels
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 
- Static Public Member Functions inherited from Standard_Transient
static constexpr const charget_type_name ()
 Returns a type descriptor about this object.
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class.
 

Detailed Description

This class compares two images pixel-by-pixel. It uses the following methods to ignore the difference between images:

Border filter ignores a difference in implementation of anti-aliasing and other effects on boundary of a shape. The triangles of a boundary zone are usually located so that their normals point aside the user (about 90 degree between the normal and the direction to the user's eye). Deflection of the light for such a triangle depends on implementation of the video driver. In order to skip this difference the following algorithm is used: a) "Different" pixels are grouped and checked on "one-pixel width line". indeed, the pixels may represent not a line, but any curve. But the width of this curve should be not more than a pixel. This group of pixels become a candidate to be ignored because of boundary effect. b) The group of pixels is checked on belonging to a "shape". Neighbour pixels are checked from the reference image. This test confirms a fact that the group of pixels belongs to a shape and represent a boundary of the shape. In this case the whole group of pixels is ignored (considered as same). Otherwise, the group of pixels may represent a geometrical curve in the viewer 3D and should be considered as "different".

References:

  1. http://pdiff.sourceforge.net/ypg01.pdf
  2. http://pdiff.sourceforge.net/metric.html
  3. http://www.cs.ucf.edu/~sumant/publications/sig99.pdf
  4. http://www.worldscientific.com/worldscibooks/10.1142/2641#t=toc (there is a list of articles and books in PDF format)

Constructor & Destructor Documentation

◆ Image_Diff()

Image_Diff::Image_Diff ( )

An empty constructor. Init() should be called for initialization.

◆ ~Image_Diff()

Image_Diff::~Image_Diff ( )
override

Destructor.

Member Function Documentation

◆ ColorTolerance()

double Image_Diff::ColorTolerance ( ) const
inline

Color tolerance for equality check.

◆ Compare()

int Image_Diff::Compare ( )

Compares two images. It returns a number of different pixels (or groups of pixels). It returns -1 if algorithm not initialized before.

◆ ignoreBorderEffect()

int Image_Diff::ignoreBorderEffect ( )
protected

Perform border filter algorithm.

◆ Init() [1/2]

bool Image_Diff::Init ( const occ::handle< Image_PixMap > & theImageRef,
const occ::handle< Image_PixMap > & theImageNew,
const bool theToBlackWhite = false )

Initialize algorithm by two images.

Returns
false if images has different or unsupported pixel format.

◆ Init() [2/2]

bool Image_Diff::Init ( const TCollection_AsciiString & theImgPathRef,
const TCollection_AsciiString & theImgPathNew,
const bool theToBlackWhite = false )

Initialize algorithm by two images (will be loaded from files).

Returns
false if images couldn't be opened or their format is unsupported.

◆ IsBorderFilterOn()

bool Image_Diff::IsBorderFilterOn ( ) const
inline

Returns a flag of taking into account (ignoring) a border effect in comparison of images.

◆ PackXY()

static int Image_Diff::PackXY ( uint16_t theX,
uint16_t theY )
inlinestaticprotected

Map two pixel coordinates to 32-bit integer.

◆ releaseGroupsOfDiffPixels()

void Image_Diff::releaseGroupsOfDiffPixels ( )
protected

Release dynamically allocated memory.

◆ SaveDiffImage() [1/2]

bool Image_Diff::SaveDiffImage ( const TCollection_AsciiString & theDiffPath) const

Saves a difference between two images as white pixels on black background.

◆ SaveDiffImage() [2/2]

bool Image_Diff::SaveDiffImage ( Image_PixMap & theDiffImage) const

Saves a difference between two images as white pixels on black background.

◆ SetBorderFilterOn()

void Image_Diff::SetBorderFilterOn ( const bool theToIgnore)
inline

Sets taking into account (ignoring) a "border effect" on comparison of images. The border effect is caused by a border of shaded shapes in the viewer 3d. Triangles of this area are located at about 0 or 90 degrees to the user. Therefore, they deflect light differently according to implementation of a video card driver. This flag allows to detect such a "border" area and skip it from comparison of images. Filter turned OFF by default.

◆ SetColorTolerance()

void Image_Diff::SetColorTolerance ( const double theTolerance)
inline

Color tolerance for equality check. Should be within range 0..1: Corresponds to a difference between white and black colors (maximum difference). By default, the tolerance is equal to 0 thus equality check will return false for any different colors.

◆ UnpackX()

static uint16_t Image_Diff::UnpackX ( int theXY)
inlinestaticprotected

Get pixel X coordinate from 32-bit packed integer.

◆ UnpackY()

static uint16_t Image_Diff::UnpackY ( int theXY)
inlinestaticprotected

Get pixel Y coordinate from 32-bit packed integer.

Field Documentation

◆ myColorTolerance

double Image_Diff::myColorTolerance
protected

tolerance for equality check (0..1, 0 - any not equal, 1 - opposite colors)

◆ myDiffPixels

NCollection_DynamicArray<int> Image_Diff::myDiffPixels
protected

coordinates of different pixels, packed in one int using 16-bit integers to save memory

◆ myGroupsOfDiffPixels

NCollection_List<occ::handle<TColStd_HPackedMapOfInteger> > Image_Diff::myGroupsOfDiffPixels
protected

◆ myImageNew

occ::handle<Image_PixMap> Image_Diff::myImageNew
protected

new image to compare (to)

◆ myImageRef

occ::handle<Image_PixMap> Image_Diff::myImageRef
protected

reference image to compare (from)

◆ myIsBorderFilterOn

bool Image_Diff::myIsBorderFilterOn
protected

perform algorithm with border effect filter

◆ myLinearGroups

TColStd_PackedMapOfInteger Image_Diff::myLinearGroups
protected

The documentation for this class was generated from the following file: