Programatically extract pattern from image file and / or PSD - php

I often have to extract a pattern from a PSD to make an image to be used with XHTML and CSS.
I have often just made a guess in Photoshop, and then had to correct my guesses a few time after. It seems cumbersome.
Is there...
Techniques for extracting a pattern from a Photoshop file with the selector tool?
A Photoshop plugin perhaps that can do this
Software that can parse a pattern image, and give me back the bare minimum to make a tiled pattern?
Should I just be requesting a copy of the pattern in addition to each PSD I receieve?
How have other people in my position tackled this problem before?
In matter of interest, how could / would I program something like this (I could use PHP with GD library)? Is it not worth my time? Would I loop through pixels left to right, and then identify image colours, and positions away from each other, and constantly check if new pixels are beginning to match an older pattern?

I'm currently working on a software that does this (and a couple more things to automate slicing of PSDs), but it's very slow even in C++. Right now i'm looking into GPU accelerated solution...
So if there's an option for requesting pattern you should just do that.

Related

php - Improving zbar recognition of scanned qr codes

I'm trying to read scanned qr codes from php, running zbarimg via exec. Working not-too-bad.
The issue is that it seems to choke on scanning artifacts like these small dots:
I've been trying to get rid of the white dots syndrome by fiddling around with Imagick - changing brightness/contrast/sharpness seems to make them stand out less but some, like this one, are still unreadable.
Is there a way to remove the white dots / improve zbarimg's recognition?
Edit:
One thing I forgot to point out:
What strikes me as weird is the fact that scanning the QR via smartphone, using the camera, reads the code succesfully in a single instant without a single issue, which leads me to think this "fixing up" shouldn't even be needed.
Am I just using zbar the wrong way?
Or do mobile OSes just use a different, better, algorithm? I tried using a zxing wrapper for PHP as well, but it gave even less results compared to zbar.
In terms of cleaning up the image you have shown us, the obvious approach would be to use cellular automata - although for best results you would ant to modify the behaviour to encompass the sharpening and thresholding you are already applying using other filters. You might consider setting the size of the cell to, say, one 25th of the QR code block resolution rather than a 1:1 with pixels in the unerdlying image. Really you should be applying your thresholding via a histogram based approach (assuming that you can isolate the QR code in the image).
I'm not aware of an implementation in PHP but there is at least one OpenCV interface for PHP

What's the name of an algorithm that would produce this graphic fill

I'm looking for an algorithm to do this effect, but it's not helping that I don't even know what to look for. I use PHP, so any existing code samples would be great. I want to specify the borders of the shape and have php auto fill it with letters. I'm also open to other ideas to accomplish the same thing. Does this algorithm have a name?
I do not know the exact name of the algorithm - I would imagine that it is a variant of the 2D bin packing problem, but without having the interest of the best possible pack.
Here are some resources and questions:
Are you trying to paint the image as tightly as possible using different sized fonts? (as opposed to all one size of font)
Can characters be cutoff at the edges?
If question two is yes, it would seem to me that the easiest way to produce the image would be to fill the entire rectangle with characters, inverse the image shape and use it as a mask.
Here is an answer for not just characters, but entire sentences. Algorithm for Text Wrapping Within a Shape
Edit:
Some popular modern graphic fill websites that could be worthwhile to study
http://www.tagxedo.com/
really fancy tag cloud shapes
http://www.shapecollage.com/
collages from images into a specific shape

Recognizable numbers using PHP

I’m trying to extract some numbers ranging from 1-99 from a picture. I’ve tried several OCR methods using PHP, but eventually my script will fail, since the numbers occasionally is rotated 5% to the left or right. This making the picture not being recognizable.
I’ve now installed Ocropus http://code.google.com/p/ocropus/ as a test. Unfortunately this is not giving me the correct numbers every time. This leads me to think that my pictures are not optimized enough.
Does anyone have some tips/ideas how to optimize the readability of the numbers? I would also be grateful for ideas how to find the numbers from the picture.
It seems that Tesseract / Ocropus are getting confused with the skew an it could be that multiple skewed numbers on the same line is confusing the Tesseract or Ocropus.
Are you passing in the whole image as a grid of numbers ? Have you tried sending each box (number) individually as a separate image to the OCR engine ? You may find you get better results.
Have you tried any other OCR engines ? Do you require it to be open source ?
I ran the image through a cheaper commercial OCR engine and all numbers recognised correctly. So another option is to wrap up a commercial OCR engine quite quickly with C# or C++ code and interface to deliver improved results.
Is it acceptable to use an external (web-based) API for your solution?
If so, please consider http://www.wisetrend.com/wisetrend_ocr_cloud.shtml (a REST API for OCR)
It can automatically correct for image rotation; Try tweaking the Deskew and AnalysisMode parameters described in http://www.wisetrend.com/WiseTREND_Online_OCR_API_v2.0.htm
(Also, when using the API, make sure that the image resolution is correctly set in the input image header - it can make all the difference in recognition quality).

Recognize image with PHP

I run a site with lots of small images (www.iconfinder.com) and would like to develop a feature that can compare and recognize images. A user should be able to upload an image (icon) and then the site will respond with information about the image if it's in the database.
What is the approach to finding similar (or the same image). I know I can compare md5 of the two images, but I also want be able to find matches if the are scaled.
This is a good start if you are interested in looking at doing it in PHP:
http://www.intelliot.com/blog/2008/03/sorted-directory-listing-image-resizing-comparison-and-similarity-in-php/
There probably aren't a lot of languages LESS suited to this task than PHP. You should really look for an image comparison library with a C compatible API and figure out how to glue that into your PHP application.
Identical images can be checked with an md5sum, but detecting if somebody uploads a scaled image, which displays the same thing as the other is very hard. This requires digital image processing.
An approach is to scale down all images to a certain width (say 100px). Then check a few coordinates for the color. If another image matches a big part (say 80%), it might be the same image.
But if the image is lighter... this won't work.

What is a good algorithm or library for cropping images to avoid whitespace or empty areas?

I have a whole bunch of images of illustrations that I would like to crop to a smaller preview size.
The problem is that I want to crop them to show an "interesting" part of the illustration (ie avoid areas of whitespace).
The images typically have a flat color or a subtle gradient for the background. They are mostly vector style artwork with fairly distinct shapes.
Here are some examples: link ;-)
I've been thinking about using some sort of image feature detection algorithm with a sliding window to find the area with the greatest number of features.
I'm implementing this in PHP, but I don't mind implementing it myself if there isn't a library or extension available.
Ideas?
ImageMagick has a trim operation. It's available as a library but I don't know how hard it is to use from PHP. There are some PHP interfaces.
OK, so here's what I would've done, after looking at the examples:
Sum all rows and all columns of each image. You'll get two arrays, both looking like this:
/-----\ /--\
_/ -- |
___- \_________
By looking at these arrays for a few images, find a suitable threshold (probably something just above zero). Then the leftmost and the rightmost crossing of this threshold is where you have to crop. I hope I've managed to make it clear enough, if not -- ask!
Here's a fairly simple approach using an edge-detection filter, and then cropping around the center-of-edginess of the image to generate a thumbnail. It works pretty well on most images, but not if there are more than one subject. I'm open to suggestions on other ways of identifying the "interesting" points in a source image.
Well, you might want to consider just using an edge detection algorithm. Pick the area with the largest number of edges. Give higher weight to edges that are not blurry (as they may be from the background).
ImageMagick for PHP has automated generation of thumbnails. This SO question has a link to an ImageMagick auto-crop operator, and I'm not sure, but I think this is the PHP interface to it.
From the link:
bool Imagick::trimImage ( float
$fuzz )
Remove edges that are
the background color from the image.
For more general "interestingness", maybe try an inverse of seam carving (to find the highest energy, rather than lowest energy areas).
A CLI program using http://pecl.php.net/package/imagick:
<?php
dl('imagick.so');
$img = new Imagick();
$img->readImage($argv[1]);
# (* 0.0: exact match; * 1.0: crop entire image)
$fuzz = current($img->getQuantumRange()) * 0.25;
$img->trimImage($fuzz);
$img->writeImage($argv[2]);
?>
It should work good enough, as long as the image doesn't have a frame around its border.
Drupal has a project called smartcrop, which has PHP code to find highest entropy and "interesting" areas in images. See the output examples.
You should be able to use the functions in the module and the library in none-Drupal projects too.

Categories