Remove photo from collage if it is plain/blank e.g sky
Remove photo from collage if it is plain/blank e.g sky
Going back to some of my old code after reading a magazine artical I need to remove photos that are of not importance e.g. sky.
In the artical there was a bridge made up of photos but only the photos of the bridge - high energy photos ? - photos of the sky and water were not used.
This is not a great example but I had it to hand on my PC. I want all the photos except the top right photo which I want converted to transparent so it does not break the code/photo collage.
Is there an easy way to determin if a photo is mostly one colour or boring!
In the artical there was a bridge made up of photos but only the photos of the bridge - high energy photos ? - photos of the sky and water were not used.
This is not a great example but I had it to hand on my PC. I want all the photos except the top right photo which I want converted to transparent so it does not break the code/photo collage.
Is there an easy way to determin if a photo is mostly one colour or boring!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove photo from collage if it is plain/blank e.g sky
if the photos are separate (i.e. before you collage them), then just check the standard deviation. If less than some critical amount, then it is flat (constant color).
convert image -format "%[fx:standard_deviation]" info:
range 0 to 1
or
convert image -format "%[standard_deviation]" info:
range 0 to quantumrange
convert image -format "%[fx:standard_deviation]" info:
range 0 to 1
or
convert image -format "%[standard_deviation]" info:
range 0 to quantumrange
Re: Remove photo from collage if it is plain/blank e.g sky
Output from your methods Fred contains a couple of strange results but works:
Method 1:
Method 2:
Method one works better; I mentioned energy in my original post as that is something used in Liquid rescale from memory but I have no idea how it would be found.
I will have to find a better image to try it on.
Method 1:
Method 2:
Method one works better; I mentioned energy in my original post as that is something used in Liquid rescale from memory but I have no idea how it would be found.
I will have to find a better image to try it on.
Re: Remove photo from collage if it is plain/blank e.g sky
Results are very dependent on input image so not realy a practical application.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove photo from collage if it is plain/blank e.g sky
It is strange that methods 1 and 2 would differ as they should be exactly scalable by quantumrange. So it must be that you chose a different threshold between the two measure (allowing for scaling by quantum range).
Yes, the threshold you choose probably should vary by data set as each set of images will have different characteristics. I know of no global measure that will work with all image sets. It really depends on the content of the image sets and how much you are willing to tolerate.
You could try my script, entropy, as a measure, if you can run this from PHP and not from the command line as I know you are on Windows. If that works, then perhaps it should be added to the IM stats information along with mean, min, max and std, etc.
Yes, the threshold you choose probably should vary by data set as each set of images will have different characteristics. I know of no global measure that will work with all image sets. It really depends on the content of the image sets and how much you are willing to tolerate.
You could try my script, entropy, as a measure, if you can run this from PHP and not from the command line as I know you are on Windows. If that works, then perhaps it should be added to the IM stats information along with mean, min, max and std, etc.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Remove photo from collage if it is plain/blank e.g sky
More than likely it is a result of exactly what standard deviation is being used. Specifically if it is a specific channel, or all the channels. Perhaps a standard deviation of just a grayscale version of the image will work better for determining how variable the intensity is.
Also you may like to run the image through a edge detector, before doing a standard deviation. That will make any image with an edge much more important than those with only gradual changes, something that standard deviation may miss.
Also you may like to run the image through a edge detector, before doing a standard deviation. That will make any image with an edge much more important than those with only gradual changes, something that standard deviation may miss.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove photo from collage if it is plain/blank e.g sky
Anthony's idea of edge detection makes a lot of sense. One could also edge detect (and threshold or autolevel) and then get the mean rather than std.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Remove photo from collage if it is plain/blank e.g sky
Which will get you a percentage of edges, though that would be dependant on image size.fmw42 wrote:Anthony's idea of edge detection makes a lot of sense. One could also edge detect (and threshold or autolevel) and then get the mean rather than std.
Essentually what you are asking is a sort of 'energy level' contained by the image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove photo from collage if it is plain/blank e.g sky
try my entropy scriptEssentually what you are asking is a sort of 'energy level' contained by the image.
Re: Remove photo from collage if it is plain/blank e.g sky
I did mention this earlier as it is the method Liquid rescale?Essentually what you are asking is a sort of 'energy level' contained by the image.
For the two outputs showing the values I used the examples as Fred posted:
Code: Select all
convert $filename -format "%[standard_deviation]" info:
convert $filename -format "%[fx:standard_deviation]" info:
I will give your entropy script a try over the weekend.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove photo from collage if it is plain/blank e.g sky
The former will produce std values in the range 0 to QuantumRangeconvert $filename -format "%[standard_deviation]" info:
convert $filename -format "%[fx:standard_deviation]" info:
The latter will produce normalized std values in the range 0 to 1
Be careful that you scale them both to similar ranges for your threshold. I usually use percent in range 0 to 100 for the std and use percents for the thresholding for the test of acceptable or not.
Note that std is like a measure of energy. It is an edge detection (if applied locally on an image) so the larger the global value, the more edges or more energy there is in the image.
Another thought/approach might be to resize the image to half or a quarter size using both -resize and -liquid-rescale. Then do a compare on the two images. The more different the more the liquid-rescale has removed low energy parts.