# Using the file hash to verify an image stimulus

**URL:** <https://mworks.discourse.group/t/using-the-file-hash-to-verify-an-image-stimulus/49>\
**Category:** Stimuli\
**Created:** [February 13, 2014, 5:06pm UTC](https://mworks.discourse.group/t/using-the-file-hash-to-verify-an-image-stimulus/49 "2014-02-13T17:06:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 13, 2014, 5:06pm UTC](https://mworks.discourse.group/t/using-the-file-hash-to-verify-an-image-stimulus/49/1 "2014-02-13T17:06:47Z")

</div>

_Available in post-0.4.4 releases of MWorks, including nightly builds since January 25, 2011_

Whenever MWorks displays an image stimulus, information about the image is logged to the data file in a `#stimDisplayUpdate` event. The event data contains two fields that identify the image file used: `filename`, which contains the full filesystem path to the image file, and `file_hash`, which contains the [SHA-1](http://en.wikipedia.org/wiki/SHA-1) hash of the image file.

Unlike the file name (which can be changed easily), the file hash provides a robust means of determining whether a given image file was in fact displayed in an experiment. The MWorks Python package includes a convenient function, `file_hash()`, that computes the hash of a file:

```
>>> from mworks import file_hash
>>> file_hash('image.png')
'e2e97203031d6c5c018aa8bfb268566a6e2d5b6a'

```

Alternatively, the `openssl` command-line tool can be used to obtain the file hash:

```
$ openssl dgst -sha1 image.png 
SHA1(image.png)= e2e97203031d6c5c018aa8bfb268566a6e2d5b6a

```

Once you have the hash for a file, you can compare it to the `file_hash` field in a `#stimDisplayUpdate` event. If the two hashes are identical, then you can be confident that the given file is indeed the image that was displayed in your experiment.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 20, 2022, 4:03pm UTC](https://mworks.discourse.group/t/using-the-file-hash-to-verify-an-image-stimulus/49/2 "2022-07-20T16:03:42Z")

</div>


