Struct img_hash::ImageHash
[−]
[src]
pub struct ImageHash { pub bitv: BitVec, pub hash_type: HashType, }
A struct representing an image processed by a perceptual hash. For efficiency, does not retain a copy of the image data after hashing.
Get an instance with ImageHash::hash()
.
Fields
bitv: BitVec
The bits of the hash
hash_type: HashType
The type of the hash
Methods
impl ImageHash
[src]
fn hash<I: HashImage>(img: &I, hash_size: u32, hash_type: HashType) -> ImageHash
Create a hash of img
with a length of hash_size * hash_size
(* 2
when using HashType::DoubleGradient
)
using the hash algorithm described by hash_type
.
fn dist(&self, other: &ImageHash) -> usize
Calculate the Hamming distance between this and other
.
Equivalent to counting the 1-bits of the XOR of the two BitVec
.
Essential to determining the perceived difference between self
and other
.
Panics
If self
and other
have differing bitv
lengths or hash_type
values.
fn dist_ratio(&self, other: &ImageHash) -> f32
Calculate the Hamming distance between self
and other
,
then normalize it to [0, 1]
, as a fraction of the total bits.
Roughly equivalent to the % difference between the two images, represented as a decimal.
See ImageHash::dist()
.
fn size(&self) -> u32
Get the hash size of this image. Should be equal to the number of bits in the hash.
fn hash_type(&self) -> HashType
Get the HashType
that this ImageHash
was created with.
fn to_bytes(&self) -> Vec<u8>
Build a grayscale image using the bits of the hash,
setting pixels to white (0xff
) for 0
and black (0x00
) for 1
.
fn from_base64(encoded_hash: &str) -> Result<ImageHash, FromBase64Error>
Create an ImageHash
instance from the given Base64-encoded string.
Note:
Not compatible with Base64-encoded strings created before HashType
was added.
Does not preserve the internal value of HashType::UserDCT
.
Errors:
Returns a FromBase64Error::InvalidBase64Length when trying to hash a zero-length string
fn to_base64(&self) -> String
Get a Base64 string representing the bits of this hash.
Mostly for printing convenience.
Trait Implementations
impl PartialEq for ImageHash
[src]
fn eq(&self, __arg_0: &ImageHash) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &ImageHash) -> bool
This method tests for !=
.
impl Eq for ImageHash
[src]
impl Hash for ImageHash
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for ImageHash
[src]
impl Clone for ImageHash
[src]
fn clone(&self) -> ImageHash
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more