Struct img_hash::ImageHash [−][src]
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]
impl ImageHash
pub fn hash<I: HashImage>(
img: &I,
hash_size: u32,
hash_type: HashType
) -> ImageHash
[src]
pub 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
.
pub fn dist(&self, other: &ImageHash) -> usize
[src]
pub 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.
pub fn dist_ratio(&self, other: &ImageHash) -> f32
[src]
pub 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()
.
pub fn size(&self) -> u32
[src]
pub fn size(&self) -> u32
Get the hash size of this image. Should be equal to the number of bits in the hash.
pub fn hash_type(&self) -> HashType
[src]
pub fn hash_type(&self) -> HashType
Get the HashType
that this ImageHash
was created with.
pub fn to_bytes(&self) -> Vec<u8>
[src]
pub 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
.
pub fn from_base64(encoded_hash: &str) -> Result<ImageHash, FromBase64Error>
[src]
pub 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
pub fn to_base64(&self) -> String
[src]
pub 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]
impl PartialEq for ImageHash
fn eq(&self, other: &ImageHash) -> bool
[src]
fn eq(&self, other: &ImageHash) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &ImageHash) -> bool
[src]
fn ne(&self, other: &ImageHash) -> bool
This method tests for !=
.
impl Eq for ImageHash
[src]
impl Eq for ImageHash
impl Hash for ImageHash
[src]
impl Hash for ImageHash
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &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[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for ImageHash
[src]
impl Debug for ImageHash
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for ImageHash
[src]
impl Clone for ImageHash