Enum sn0int_std::gfx::HashAlg

source ·
pub enum HashAlg {
    Mean,
    Gradient,
    VertGradient,
    DoubleGradient,
    Blockhash,
    Median,
    // some variants omitted
}
Expand description

Hash algorithms implemented by this crate.

Implemented primarily based on the high-level descriptions on the blog Hacker Factor written by Dr. Neal Krawetz: http://www.hackerfactor.com/

Note that hash_width and hash_height in these docs refer to the parameters of HasherConfig::hash_size().

Choosing an Algorithm

Each algorithm has different performance characteristics

Variants§

§

Mean

The Mean hashing algorithm.

The image is converted to grayscale, scaled down to hash_width x hash_height, the mean pixel value is taken, and then the hash bits are generated by comparing the pixels of the descaled image to the mean.

This is the most basic hash algorithm supported, resistant only to changes in resolution, aspect ratio, and overall brightness.

Further Reading: http://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html

§

Gradient

The Gradient hashing algorithm.

The image is converted to grayscale, scaled down to (hash_width + 1) x hash_height, and then in row-major order the pixels are compared with each other, setting bits in the hash for each comparison. The extra pixel is needed to have hash_width comparisons per row.

This hash algorithm is as fast or faster than Mean (because it only traverses the hash data once) and is more resistant to changes than Mean.

Further Reading: http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html

§

VertGradient

The Vertical-Gradient hashing algorithm.

Equivalent to Gradient but operating on the columns of the image instead of the rows.

§

DoubleGradient

The Double-Gradient hashing algorithm.

An advanced version of Gradient; resizes the grayscaled image to (width / 2 + 1) x (height / 2 + 1) and compares columns in addition to rows.

This algorithm is slightly slower than Gradient (resizing the image dwarfs the hash time in most cases) but the extra comparison direction may improve results (though you might want to consider increasing hash_size to accommodate the extra comparisons).

§

Blockhash

The Blockhash.io algorithm.

Compared to the other algorithms, this does not require any preprocessing steps and so may be significantly faster at the cost of some resilience.

The algorithm is described in a high level here: https://github.com/commonsmachinery/blockhash-rfc/blob/master/main.md

§

Median

The Median hashing algorithm.

This is a variation of the Mean hashing algorithm that uses the median instead of the mean for filtering. This variation is discussed in the further reading section, and an implementation can be found here https://github.com/JohannesBuchner/imagehash/blob/4de9becdb13ecad67b7393cc17b5a44ea1c61b6b/imagehash.py#L193:

Further Reading: http://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html

Trait Implementations§

source§

impl Clone for HashAlg

source§

fn clone(&self) -> HashAlg

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HashAlg

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for HashAlg

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<HashAlg, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<HashAlg> for HashAlg

source§

fn eq(&self, other: &HashAlg) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for HashAlg

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for HashAlg

source§

impl Eq for HashAlg

source§

impl StructuralEq for HashAlg

source§

impl StructuralPartialEq for HashAlg

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

source§

fn is_within(&self, b: &G2) -> bool

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,