Jump to content

Recommended Posts

This may be a bit far-out :o. Firstly not that hard I'd image, can PHP get the colour information of an image? Like return a value that could indicate that most of the image is e.g. black.

 

Second, can it apply a 3d matrix over an image and rotate it so its like scanning the image, e.g if the picture has a big 30 made out of cheese on it, can php stick a 3d 30 over the image and spin it around, resize it etc etc until the 3d matrix has matched the shape of the 30 in the image (youd give it say 10 seconds to scan, if not matched in the time limit then move on to next image).

 

With some margin of error of course (may not be a perfectly shaped 30) then have it do something when a match is found e.g. say “this picture has an item that looks like a 30”?

 

Or is that way beyond todays php :(?

 

Link to comment
https://forums.phpfreaks.com/topic/154281-advanced-image-scan-with-php/
Share on other sites

you can do a nested for loop to go pixel by pixel and populate an color=>count of all the different colors and then divide each count by total pixels * 100 to get the percentage of each color in the image.  I'm quite sure I've seen plenty of scripts that already do this, if you don't wanna write that yourself.  Not that this step is any kind of difficult...5-10 lines tops.

 

create image source

for loop

  for loop

    get pixel info

    $color[rgb]++;

  }

}

$totalpixels = array_sum($color);

foreach ($color as $k => $v) {

  $color[$k] = $v / $totalpixels * 100;

}

 

As far as the whole scanning thing, there would be a big margin of error and unreliability, regardless of what you try to do.  I personally would initially approach it by filtering the image down to only a couple of colors (think along the same lines of in paint/image editing programs, the "outline horizontile/vertical" feature, or the "emboss" feature) first.  Ideally straight black and white. 

 

From there I would...try to come up with a way to find the boundaries of the shape. Maybe something involving overlaying the image with a grid and looping through x1,y1,x2,y2 cell coord for presence of pixels.

 

As a first version, I would just compare it as if it were a solid shape.  a "swiss cheese" 3 would ideally match less than a solid 3 for example, but figuring it out at that level of granularity would pretty much involve recursively repleating some of these steps. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.