EDIT:
Is there a way to jumble arround the pixelated elements? If I have a grid of lets say 100x100 - then the pixels get very small and you can see the image sort of. So I'd like to jumble the pixelated parts. Any idea?
I'm trying to use PHP to divide an image into an equal grid, so that I could pixelate it into even parts.
It has to do with a sort of game. There is an image uploaded by some user, and I want it to be divided into x blocks (the user selects how many blocks there should be), each of the blocks would then be pixelated. When other users complete some task - one part of the pixelated block is revealed, until all pixelated parts are gone and you're left with the original image. I really don't care if the grid elements are squares, or rectangles - I just want them to be even.
As my starting points, I'm using the answer on this question PHP image pixelate?
To determine the x and y pixel size, I'm using this formula:
$gridElements = 9;
$pixelate_x = $width/sqrt($gridElements);
$pixelate_y = $height/sqrt($gridElements);
I've noticed that when using a number, whose square root is an integer - I get a more even grid.. But it's not perfect.
When trying out with a 9 block grid, and using a 1160x680 image, I get the following:
It may appear to look even, but the last row is bigger than the top 2 rows.
When I scale it to 16, the difference is quite obvious
And when trying out a 400 element grid (20x20) the 21th row appears.
So .. It's not working very well, I do want the grid to be even. Does anyone have any idea of how this could be done?
This is because 1160 doesn't really divides itself very well, even by 3 (yes, it is not equal when using 3x3 grid either). Your greatest enemy here are integers
Related
thanks for looking at my question.
Basically what I'm trying to do is find all images that look like the first and the third image here: http://imgur.com/a/IhHEC
and remove all the ones that don't look like that (2,4).
I've tried several libraries to no avail.
Another acceptable way to do this is to check if the images contain "Code:", as that string is in each one that I have to sort out.
Thank you,
Steve
EDIT: Although the 1st and 3rd images seem like they are the same size, they are not.
If those are the actual images you're going to use, it looks like histogram similarity will do the job. The first and third are very contrasty, the second and fourth, especially the fourth, have a wide range of different intensities.
You could easily make a histogram of the shades of grey in the image and then apply thresholds to the shape of the histogram to classify them.
EDIT: To actually do this: you can iterate through every pixel and create an array of pixel value => number of times found. As it's greyscale you can take either the R, G or B channel. Then divide each number by the number of pixels in the image to normalise, so it will work for any size. Each entry in the histogram will then be a fraction of the number of pixels used. You can then measure the number of values above a certain threshold. If there are lots of greys, you'll get a large number of small values. If there aren't, you'll get a small number of large values.
Due to my background in working more with text from images than image objects, I would do this in post-OCR process, by searching the text content for 'keywords' or checking for 'regular expression' representing your desired data. This means that the entire job needs to be separated into two stages: image-to-text OCR (free or cheap, software or cloud), and actual separation process (simple programming).
I am working on a web project, and I am thinking on how to best approach the following scenario:
I have a bunch of images in a database and I want to load this in a grid. High ranked images need to have a bigger canvas, while lower/not ranked ones don't. The size of the images are not standard so it could be either a portrait or a landscape picture with each different sizes. The aspect ratio needs to remain intact, and the window needs to be totally filled horizontally (with a width of 100%). Users can scroll vertically.
To give you an idea of the division of the fields in the grid, I have attached a quick wireframe.
Do you guys have an idea on how to approach this best? I was thinking maybe I should "standardize" a few rows. And place the rows randomly so that it does not look pre-set. But this is obviously not really calculated. Any thoughts are appreciated!
Ended up using Masonry
http://masonry.desandro.com/
I set the width of each individual column, by dividing the window.width by 5.
If this grid is working for you http://css-tricks.com/13372-seamless-responsive-photo-grid/ you can look for a 1d bin-packing algorithm. This algorithm tiles the screen into vertical bins of the same width. Then it looks into your collection for the first-fit, the best-fit, next-fit or the worst-fit. You can combine each method with a random order, a decreasing order, or an increasing order. This is a very hard problem to solve, maybe you want to try a brute-force solution?
I'm trying to find some way to convert a number 1 - 5 into a star rating, which can also accomodate decimals, like 4.3 or 3.34, and be very precise (like on Amazon.com). The rating doesn't have to be usable, it just has to be a static image. Any help?
I'm fine with using PHP or jQuery, whichever it needs to be.
You could create an image that is white with transparent star cutouts. Then place that over the top of a yellow div of a given length. Lets say your image was 100px wide. If you had a 3 star rating you would make the yellow div 100*(3/5) and 3 of the stars would be filled in.
EDIT:
A similar idea. You could have an image with all 5 stars on it. Place this image within a div with overflow:hidden. Then you set the width of the div the same way as above. The smaller the div the less stars you'll see.
EDIT2:
Fiddle just for fun. All the granularity you could ask for.
http://jsfiddle.net/qFMyC/
This must be sufficient for your purpose:
http://www.fyneworks.com/jquery/star-rating/#tab-Testing
I wrote this ages ago. I was obsessed with not using JS. It needs some work, but I think it's exactly what you're looking for.
http://yefomit.com/internet/simple_css_rater
I'm hoping you mean turning the 1 -5 value into an actual star representation.
It depends how granular you want to be, I think Amazon's is accurate to tenth's (0.1), this is probably achieved server side to save on client load and take advantage of caching the images; but it could be done client side.
#kingjiv posted a good client side solution but for server side:
If you're not too worried about granularity you could create 11 images 0, 0.5, 1, 1.5 etc. etc. and pass the value into the image src attribute. This would serve the right image and they'd be nicely cached for re-use over and over on your pages.
If you want to be really granular though you could create them in code server side, cache them on creation each time ready for quickly serving afterwards. With this method you could go to whatever degree of accuracy took your fancy.
For PHP I'd recommend looking at Imagik
What I have done in the past is to create 2 divs and put them on top of each other.
On the bottom div you set the width equal to the width of 5 stars. So, if your star is 50px wide, your bottom div is 250px wide.
On the top div you use the same star with a different color. Then you set the width of that div in php or javascript to 50 * $decimalStarRating.
I've got a security camera set up, and i'm comparing 1 minute batches of images to check if there's been any motion. I have 10 coordinates that I check between each image. If any pixels don't match the previous image, it triggers a warning message.
Problem is, it works too well.
The logic is basically if imagecolorat() is greater or less than a 10% difference from the previous imagecolorat(), it triggers. So, if a cloud comes over the house, it triggers. Basically any change in light triggers it. So, I've moved the threshold from 10% to 30% and it triggers less but I'm worried now that if I move any past that, real motion wont be detected.
Note: I'm using the raw output of imagecolorat(), not the RGB values. I'm not sure if this would have an impact.
You are looking for larger discontinuities - things like noise and slow variation should be discounted (unless this motion detection is for very slow moving small things, like garden gnomes).
Therefore, do a histogram equalize or something similar before image subtraction to account for global shifts in light, and do some filtering / edge enhancement before differencing to enhance the changes. Using more of the image will be better I would think, than just 10 points.
Histogram equalization entails looping through the image, and counting bins for each brightness value - so you have a resulting data set that says how many pixels are in a set of tonal ranges. In other words, say you divvy up into 16 bins - pixels that have a greyscale value (or alternately, the Brightness in an HSB model) in the value of 0..15 (assuming an 8 bit image here in this channel) are all in bin 1. Then you go forth and compute a series of linear stretches to apply to each bin so that it occupies an output range in proportion to its population. So if ALL of your pixels are in the 0.. 15 bin, you would just multiply everything by 16 to stretch them out. The goal is that your histogram of your equalized image is flat - equal amounts of pixel in every bin.
Edge enhancement can be simply done with the application of a Sobel filter.
The project is developed using CakePHP.
The page is of a news feed article.
Pagination is simple when you want to return (x) number of records per page, or (x) number of images per page, or even limit the number of words/paragraphs/characters but what if you want to paginate by the visual length of the page?
The issue came up because some articles contain a large amount of text and a large amount of images. I would like to know how you would go about developing pagination when the content is completely dynamic. By this I mean, it could be 100% text, text and 3 pictures, 10 pictures, etc.
Code is appreciated but even a concept would be beneficial, thanks!
I don't know cakephp, but, how about counting the number of characters?
Let's say you have 10.000 characters in the article and you decide that each page should have not much more than 500 words. Given an average word lenght of 5 characters, you go to the character 500*5=2500, look for the next closing paragraph, and take this point as next-page mark.
You could use the same concept with images but considering the height of the images...
Sounds good?
Because we know the width of the page and the height of the image and we were able to approximate the pixel height of the text.
We then took the height of the images, spaces, and text, and subtracted that from the total allowable height within a certain percentage of error, this is so that it doesn't push an image onto the wrong page just because the last 10px go over the limit.
We also have a way to force items onto the previous page in the event that an image, or sentence gets pushed to the next page which does not give the proper look.