softawaregmbh / smartcrop.net

A .NET Standard implementation of smartcrop.js for content aware image cropping.
MIT License
43 stars 6 forks source link

Image format causes inverted y-coordinates in crop result #4

Closed SaberSnail closed 4 years ago

SaberSnail commented 4 years ago

I used the Smartcrop.Sample.Wpf application on the following image to crop to 194px wide by 109px high: Charles Spurgeon

The resulting crop was unexpected: BadCrop

After some debugging, I noticed that the y-coordinate of the cropping location appeared to be inverted.

At some point, I ended up converting this image to a png file: Charles Spurgeon

When I used the sample application on this image with the same crop size, the coordinates came out as expected: GoodCrop

I can't see any obvious reason why the two images would crop differently.

Skleni commented 4 years ago

If you compare the color values of the two images, they're not exactly the same. For example, the top left pixel in the jpg has the color #2C2535 while the same pixel's color in the png is #2D2735.

The different colors result in different scores:

Here are the scores for the area containing the face for jpg (left) and png (right):

image

And for the area containing the hands:

image

Apparently the slightly different jpg colors get a better score in the skin category for the hands.

The original implementation seems to have the same issue. Depending on your needs, you might be able to achieve better results by using different weights for the individual scores.

SaberSnail commented 4 years ago

Thanks for looking into this.