Content Based Image Censoring Class

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
I have been working on this for a while and ideally need some help to tidy it up as it's my first OOP.

Effectively, I wanted a class that analyses images to check for skin tone percentage. Then return the original image if the percentage is low enough, but return a pixellated image if it is too high together with the option of a link to view the original. Quite a challenge!

I have now succeeded (tested it and it works), but I'm guessing the code is messy and resource intensive so I'm asking if anyone a) finds this of interest and b) would like to assist in making the code cleaner.

There are 3 files attached

1) The class (a lot of commented out stuff here that I used to determine what a skintone is)
2) A dynamic pixellated image renderer (same directory)
4) The test html page

The class call has a number of variables to control the output.

First is the source url
Second.. if "Message" is entered rather than "", a warning message will be output.
Third.. if "Link" is entered rather than "", it will provide the link to view the original.
Fourth.. adjust the sensitivity. In this case, the percentage skintone threshold is 15%. If the image contains more than 15% skintones, it will return a pixellated image. The higher the percentage, the more skintones need to be present before pixellation.

The class will return the complete image so no need for <img src="anything"/> etc...

PHP:
$analysedImage = new ImageAnalysis();
$analysedImage->doAnalysis("thefullurl","Message","Link","15");

It doesn't seem to return pixellated images for all urls... for some reason.

This will be extremely useful for my search engine, but may be helpful to others as well.

Any ideas?
 

Attachments

  • cbic_test.txt
    1.1 KB · Views: 37
  • cbic_class.txt
    6.7 KB · Views: 34
  • cbic_pixelimage.txt
    1.1 KB · Views: 27
Last edited:

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
Sorry for the double post, but this has undergone some serious mods.

Class now returns a simple image URL (Original or pixellated), together with pass/fail variable.

the class entry variables are now source URL, sensitivity, pixellation amount.

Example can be seen working at http://www.qualityimagesearch.com/test.php

The major problem is the processing time. It's highly effective, but way too slow. I may have to dump this project.

If anyone is interested in seeing the scripts, let me know.
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Is this evaluating the image on load? If so, can it not be done when you are finding the images rather than when loading?
Also, if you plan to continue with this you'll likely want to implement an option to toggle it on or off, as it seems it gives quite a lot of false-positives that users may wish to avoid.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
The concept is flawed to begin with.

Define "skin tone".

What if the model is wearing nothing but green body paint?

What if she is wearing a green leotard with x-rated holes cut in it?

A head shot can be 90% skin tone and not 'pornographic'
 

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
Is this evaluating the image on load? If so, can it not be done when you are finding the images rather than when loading?
Also, if you plan to continue with this you'll likely want to implement an option to toggle it on or off, as it seems it gives quite a lot of false-positives that users may wish to avoid.

This is evaluating in real-time: more reliable, but much slower - probably unacceptably slow. I like your idea though. It would be simple enough to store a suitable/risk variable in the database.

The toggle system I have already though of. Adding a preferences page, with a server variable (or a cookie) would do this nicely and I could add a class variable that stops the class running.

The concept is flawed to begin with.

Define "skin tone".

What if the model is wearing nothing but green body paint?

What if she is wearing a green leotard with x-rated holes cut in it?

A head shot can be 90% skin tone and not 'pornographic'

Yeah - I had a nasty feeling someone would say this...

My second attempt (this is the 3rd) was far more complex, storing a range of rgb values as a serialised string in the database (much like a cbir system), which could then be compared using an existing stored set of example images and returning a % similarity. I assumed that this would provide a set of recognised patterns that could be compared against rather than a simple "skin tone %", but after much testing, it wasn't working how I wanted it to and I reverted backwards.

You are right - it is severely flawed, although it could be perceived as an improvement over existing image search engines.

The best method would be to recognise certain patterns within the image, but I do not have any idea how to even approach this effectively yet.

Thanks for the feedback.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The best method would be to recognise certain patterns within the image, but I do not have any idea how to even approach this effectively yet.

There was a time when neural networks were all the rage for this sort of problem, though I don't know as though they're as highly thought of these days.

You could explore image similarity algorithms. Sample images of interest (pornographic, artistic nudes, beach-goers &c). See how similar they are to each other. Record the metrics of various sample images, then compare new images to those metrics.

In the end, any non-semantic comparison is destined to fail in a noticeable number of cases. Of course, if you can get a computer to perform semantic image comparison, you'll win a Turing award.

You could base censoring not only on the image itself but side-channel information, such as the URL, the text of the page where you found the image (especially the text near the image) and the page that linked to the image page.
 

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
Damn - image similarity was how I was approaching it previously!!!

I was just getting weird results - maybe I didn't have enough comparison data.

I think this needs a major re-think....

Case closed for the time being.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Try training some neural networks. As long as you've got a large sample that you've classified, they have a decent possibility of working. The main problem will probably be that the size of the network is O(width*height) of the images, with O((width*height)**2) initial connections.
 
Top