Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embedart: write candidate image only if it is "similar" to already embedded one (suite) #974

Merged
merged 38 commits into from
Sep 25, 2014

Conversation

Kraymer
Copy link
Contributor

@Kraymer Kraymer commented Sep 21, 2014

Original issue : #848
Continuation of work started by PR #966

Taken from the docs :

The compare_threshold option defines how similar must candidate art be regarding to embedded art to be written to the file.
This works by computing the perceptual hashes (PHASH_) of the two images and checking that the difference between the two does not exceed a given threshold.
The threshold used is given by the compare_threshold option:

  • use '0' to always embed image (disable similarity check)
  • use any positive integer to define a similarity threshold. The smaller the value, the more similar the images must be. A value in the range [10,100] is recommended.

Additional commit infos :

  • 26ec2b8: I kinda hacked ArtResizer original goal, using it only to inform me if IM is installed or not. In the long term we might want to do some other basics operations and renaming the class into ArtProcessor or something would fit better I think.
  • a06c27 : what's tricky here is that compare return code is 1 in case of non match, yet the two images in such case may be judged as similar from a human point of view. So I needed to interpret the printed diff value even when CalledProcessError is raised. Maybe this edit to command_output could be done more elegantly ?
  • 187497c: I don't know what range of values can compare -metric PHASH return ([0, ?]), so I decided to let user set the threshold and hinting at a reasonable max in the docs (100)

sampsyo and others added 30 commits September 15, 2014 10:25
Most clients other than Library._fetch know what type they have!
The type tests now live where they ought to live.
This turned out to be less useful than I was hoping.
Models can now have a dict of special sort classes.
The mock wasn't being triggered; these tests were going to the network. Now we
don't match on the query string and instead test that it was correct by
actually parsing it.
It would be nice to cache the Sort object so we didn't have to re-parse this
every time...
This is basically always what you want, so now you can just use the name of
the field without "smart".
This makes fast SQL queries for singletons possible
Uses the new API from the previous commit and fixes beetbox#963.

There is a possible issue with backwards compatibility: Changes to the
item in the 'write' event do not propagate to the tags anymore. But I'm
not aware of other plugins that use the API in that way.
Zero plugin can modify tags without changing the item
Fixes regression from 3197795
and makes tests from 56aba87 pass.

Fixes beetbox#970
@Kraymer
Copy link
Contributor Author

Kraymer commented Sep 21, 2014

Problem with python 2.6:

  File "/home/travis/build/sampsyo/beets/beets/util/__init__.py", line 643, in command_output
    raise subprocess.CalledProcessError(proc.returncode, cmd, stderr)
TypeError: __init__() takes exactly 3 arguments (4 given)

If someone have an idea how to work around that... by raising a custom error (matching the py2.7 error signature) that we will define at the top of the file?

@sampsyo
Copy link
Member

sampsyo commented Sep 21, 2014

Hmm... it looks like you're using this to capture the stderr of the command when the invocation fails. You probably already thought about this, but is this really necessary? Could you invoke the comparison command so that, when it fails, you know the images are too dissimilar?

Alternatively, you could consider just not using the command_output utility here; other uses of the utility don't care about the stderr so the use case is different enough to justify reimplementation.

@Kraymer
Copy link
Contributor Author

Kraymer commented Sep 21, 2014

Could you invoke the comparison command so that, when it fails, you know the images are too dissimilar?

I thought not, but after checking compare --help it seems setting -dissimilarity-threshold when calling could help.

Edit (after testing) : actually, no. Changing the dissimilarity-threshold does not yield any result regarding the return code value.

we used to parse `convert` output but `convert` happens to be a
Windows cli command too. using `identify` is less error prone.
@Kraymer
Copy link
Contributor Author

Kraymer commented Sep 24, 2014

@sampsyo if it s OK with u, I d like to merge that PR. Got another one comin up =]

@sampsyo sampsyo merged commit d2cf41f into beetbox:master Sep 25, 2014
sampsyo added a commit that referenced this pull request Sep 25, 2014
embedart: write candidate image only if it is "similar" to already embedded one (suite)
sampsyo added a commit that referenced this pull request Sep 25, 2014
@sampsyo
Copy link
Member

sampsyo commented Sep 25, 2014

LGTM! All merged up. See minor changes above (mainly docs, some style).

@Kraymer
Copy link
Contributor Author

Kraymer commented Sep 26, 2014

added a note concerning the doc.
And yeah thanks to get rid of all these passive forms I use when I write.

@Kraymer Kraymer deleted the fetchart_issue848_2 branch February 13, 2016 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants