removing artifacts in a png - php

I've created my own algorithm to remove artifacts based on pixels. The only problem is that I have to manually specify the range of RGB based on a picture.
I'm trying to make it a bit more automatic, and have concluded that artifacts are usually very light colored and barely visible unless tilting the screen. Is there any RGB math that I can use to weed these artifacts out properly?

A basic way to do this is to use an adaptive blur on the image. Very close to white will be turned white, and so on, but edges will stay intact. Use ImageMagick, http://www.php.net/manual/en/imagick.adaptiveblurimage.php

Related

Color to Black and White from PDF to IMG to PDF again

Ok, so I am taking full color PDFs and trying to convert them to black and white images to then make them black and white PDF's.
Currently I am attempting to do this with imagemagick and i am for the most part successful with breaking them PDF into separate images. However once creating the separate images I want to make full size black and white copies next to the color copies as well as thumbnails thereof of both. Which that part I feel I'll be able to figure out on my own.
What I am having trouble figuring out is how to get them to become black and white. Not necessarily grayscale, since grayscale will still use colored ink in most printers to come up with the varying shades of gray. From which I am trying to avoid.
Is there a means I can do this with imagemagick or is my thought process all wrong?
Also worth noting is I am trying to do this through a browser and server side process with PHP
I think you are looking for "Two Colour Quamtisation" as described in Anthony Thyssen's excellent work here.
Basically, you use quantisation to pick the best two colours to represent your image, then force the darker one to black and the lighter one to white. So your processing becomes:
convert image.png -colors 2 -colorspace gray -normalize result.png
Btw, I presume you found and are using pdfimages (part of the poppler package) to extract the images in original quality.

Replacing detected object in a frame with an image.(imageProcessing)

Overview:
I am working on a video creation project. The technology I am using are: imageMagick, php, ffmpeg.
Current Status:
Currently the project is able to create videos using images and texts and few basic transitions. The way I am doing it is using imagemagick to create gif using input images(with transition effects in them) and then converting all gifs to videos and atlast concatenating the video together.
Next Move (My question):
I am now set to take it to the next level. So, what I am having is a video(1920x1080) with some white frames(1280x720) that keeps shifting in each frame. I want to replace those white frames appearing in some frames of the video with some images(1280x720) that I wish to use. Please see the image here and you will get an idea: These are just two frames from my video. If you can see carefully the images are shifting(white space is not constant).
Expectation:
So, I want to fill those white space with one of my own image. If the case would have been for only one frame I could have used ffmpeg to overlay image on the exact width and height. But here the white space is not fixed and keeps shifting in all the frames and there are a lot of frames. So, I am looking for something like opencv or some other technology that can be used for object detection in a video or in a set of frames and replace the detected area with some other image.
I just need a kick. So, if anyone has already worked on something like this just suggest me what technology can I use. Thanks in advance.
It all depends on exactly what you can assume :
If you can safely assume that your rectangle's boundary is never occluded (hidden) somehow, you can try finding the edges in your image (like OpenCV's Canny edge) and then look for rectangular shape (corners forming a warped rectangle, or the very popular Hough Lines).
If the rectangle you're looking for is always white, you can threshold the image in a colorspace like HSV to look for maximum value (the V in HSV ~ brightness) then rectangular shape search in a binary image.
If your corners are occluded sometimes you'll have to do some tweaking with your image, like morphological operations ("grow and contract" binary thresholded image), then Hough Lines could do the trick.
Note that this answer assumes that once you know where the rectangle is, "you're done", and you just have to overwrite the rectangle with custom content.
I also do not check for any time-continuity : you video frame might jump around based on the frame-by-frame appearance of rectangle. You'd have to include some knowledge about previous positions.

phpOCR is not working properly

I am creating a data entry web application using phpOCR. Where user need to put the numbers that will show on image. In that purpose I am using phpOCR, but it only detect the numbers that is very clean, but I need to detect the numbers that is blur on the image.
The below image is an example of my images, where phpOCR detects only the numbers in red, not the blur numbers.
On the below image the blur number is 10-30-60.
Is there any way to solve this?
You might be able to drastically change the contrast and brightness of the image - then, possibly, those faint letters will become black, and the background completely white. The OCR may then be able to read it. But then, some things may just not be possible for the OCR to detect.

Convert white parts in image to transparent to simulate printing

I am currently developing an AJAX application using PHP and Javascript that allows people to upload images that will be printed on foil. Since I will be using a standard CMYK printer, it won't print any white parts, but rather just leave those spots blank - a thing that usually does not make a difference on white paper, but here it does, since I'm printing on foil. It gets more complicated when you consider that a grey dot will become semi-transparent black, and I'm not even talking of colors yet.
Yet I would like to create a PNG file with an alpha channel that will simulate the printing process, so I can give a preview of how the printed foil would look when being hold against different backgrounds.
Now I do understand the basic theory of subtractive and additive color models and also of RGBA and CMYK, but then again it's only the basics and here I'm kind of at a loss of how to proceed. I guess in theory you would convert every pixel into CMYK and interpret each channel as a scale from transparent to color instead of from white to color, but how would you translate that back into RGBA?
The nicest thing would, of course, be if ImageMagick would provide such a feature .... does it, or do I have to loop through the pixels manually? If the latter, how would I do the calculations?
I don't know if this has been an issue before. I couldn't find anything on either Stackoverflow or Google, but maybe I just missed the right keywords. Any further reading, food for thoughts or hyperlinks with a note "we discussed this a million times, idiot!" would be warmly welcome.
Thanks
What you basically want is to add an alpha channel to the uploaded image and create a PNG file.
The alpha channel should represent the opacity of the printed color. To generate it, you have several options:
Take a copy of the image, convert it to grayscale, invert it and use it as alpha channel.
Create an alpha channel compute the alpha value of each pixel derived from the original image as: alpha = 1.0 - min(red, green, blue) (use 255 instead of 1.0 depending on whether you're using integer or floating point numbers).
Convert the original image to CMYK (using a color profile and not the poor formulas youn find all over the internet) and use it as the basis to create the alpha channel for the original RGB image: alpha = max(cyan, magenta, yellow, black).
Come up with an even better formula to compute the transparency of each pixel such as: alpha = min(0.2 * cyan + 0.5 * magenta + 0.1 * yellow + 0.7 * black, 1.0)
The last one is just a guess of the relative opacity of each color. You can certainly improve it.

Radial gradients with opacity in PHP

I need to create a PNG radial gradient with opacity. I've looked through GDLib but I can't see a way to generate radial gradients. Does anyone know of a way with GDlib or any other graphics library for PHP?
I suppose worst-case I could generate it pixel-by-pixel using GDLib but how does one even start to do the math on that?
The goal is to generate sexy lighting effect background PNGs for web pages. An example of the effect can be seen on the header here which uses this background image. I've tried generic white lighting effect PNGs but it doesn't look anywhere near as good as tinted lighting, so my generated PNGs will take into account the website's color scheme.
I assume server-side is the way to go because browser support for CSS radial gradients is so patchy.
Why not use a combination of imagecolorallocatealpha() and imageellipse() or imagefilledellipse()?
Edit:
See this class for an example of what I mean. You should be able to extend this to support alpha.
Edit2:
I have made some modifications to the class above to yield alpha support. It's not perfect, but it works for ellipses and such:
http://codepad.org/1eZ3Km0J
the classic video game trick is to apply a gradient texture, rather than compute the light. this is a perfect use for the technique.
make a grayscale gradient at a large-ish pixel dimension (2048px square is common) and several smaller ones (1024,512,256px etc) pick the closest one for your need (scaling up may exaggerate banding, scaling down may introduce moire).
use php gd function such as imagecopymerge. depending on intent, you could store the result on first use.
I suppose worst-case I could generate
it pixel-by-pixel using GDLib but how
does one even start to do the math on
that?
The math is easy, alpha = max_alpha - (distance_to_center / radius) where the distance is Euclidean, i.e. sqrt( (x1-x2)^2 + (y1-y2)^2 ).

Categories