esimov/caire

Algorithm doesnt consider mask properly

kartikwar opened this issue · 16 comments

I was playing around with the mask parameter and I feel that the algorithm sometimes distorts the masked objects. For example in this image I marked the girl as important, still in output her face was not preserved. Is there any parameter where I can force the algorithm to not touch the masked object (like completely ignore it)

example
sal_example
output

What I can see at a first sight is that the source image and the mask image has two different size. The mask image should have exactly the same size as the source image to work properly. The logic behind is identical with the face detection: I'm just making some XOR operations with the image mask and the sobel operator, in other words the zones which have more white patches are not altered by the seam carver.

Sorry I had uploaded the wrong image. This is the correct mask image I had used
sal_example
The output is same as before

Looks like that for vertical resizing something is not working quite well. For horizontal resize this is what I got using the following command:

$ caire -in testdata/sample.jpg -out output.jpg -perc=1 -width=50 -mask "mask.jpg" -debug=1

output

This is decent output. Is there any workaround to make it work for vertical resizing as well? I need the solution for both horizontal and vertical resizing. Seems like the algorithm is not considering the top pixels for this image, those top pixels(vertical), seem very similar to the horizontal ones (at least visually). So not sure whats going wrong

I'll have to debug it. Sure it should work both for horizontal and vertical resizing equally.

Thank you @esimov.

This issue should be fixed now. You should pull out the new code changes. Let me know if it's working for you.

I pulled the latest code and ran it again, but still seeing the same output.

I am using the following commands to run the algorithm:
1.) cd cmd/caire
2.) go build main.go
3.) go run main.go -in example.jpg -out output.jpg -width=500 -height=300 -mask sal_example.jpg

Please let me know if I am doing something wrong here

output

I have completely rewritten a few parts of the seam carver algorithm. There were a few things which didn't worked properly on vertical resizing, so normally the issue should be fixed now.

I tried the latest code. There still seems to be distortion in the masked objects (sometimes moderate, sometimes severe). Also, it seems a lot of times algorithm just ignores the background leaves to carve out.

go run main.go -in example.jpg -out output.jpg -width=500 -height=300 -mask sal_example.jpg

output_latest

go run main.go -in example.jpg --perc=1 -out output.jpg -height=10 -width=50 -mask sal_example.jpg

output_height_10_width_50

I can confirm that the last example is not working as expected. I will check it soon.

Thank you @esimov. Will look forward to the solution

I closed this by mistake. Reopening it

Now it should work also when percentage is used. Right now I'm working on some updates to facilitate the GUI debugging. Once it's done and the GUI debug mode is enabled it will be much easier for everyone to get a real sense how the algorithm is working.

If you don't have any objections I would close this ticket.

Since I didn't get any response I will close this ticket.