I have a database of original images and for each original images there are various cropped versions.
This is an example of how the image look like:
Original
Horizontal Crop
Square Crop
This is a very simple example, but most images are like this, some might taken a smaller section of the original image than others.
I was looking at OpenCV in python but I'm very new to this kind of image processing.
The idea is to be able to save the cropping information separate from the image to save space and then generate all the cropping and different aspect ratio on the fly with a cache system instead.
The method you are looking for is called "template matching". You find examples here
https://docs.opencv.org/trunk/d4/dc6/tutorial_py_template_matching.html
For your problem, given the large images, it might be a good idea to constrain the search space by resizing both images by the same factor. So that searching a position that isn't as precise, but allows then to constrain the actual full pixel sized search to a smaller region around that point.
Related
I'm currently working on a image processing project opencv python based, and essentially it's quite simple, it uses cv2.matchTemplate and a database to make all the matches, but I think something is done wrong.
The images are get from a few cameras, then the processing starts, based on predefined masks, the ROI of each object is returned the ROI of to then be matched with a database of images.
The problem is, the database has crops are the same size of the ROI predefined, which means the cv2.matchTemplate is always trying to match an image of the same size as the one in the database.
Here's an example with a printed circuit board (which is what my project does, it looks for bad positioned components/missing components).
Simple circuit board
This would be the full raw image, taken from one of the cameras.
Next a predefined filter would be applied to the raw image, I usually convert it to grayscale.
Now, my predefined ROI would crop the image.
Image ROI
Image crop
Notice though it crops way more than the component itself, and this crop will be saved in the database for eventual matches.
But shouldn't I be manually feeding my database with properly images? I mean, is it ideal? wouldn't it take way more matches (images) to get my desired threshold?
I need arguments to convince someone of it, I want to feed my database with well cropped images, but this person just wants to save it automatically.
Thanks!
I find many examples of passing a list of images, and returning a stitched image, but not much information about how these images have beeen stitched together.
In a project, we have a camera fixed still, pointing down, and coveyers pass underneath. The program detects objects and start recording images. However some objects do not enter completely in the image, so we need to capture multiple images and stich then together, but we need to know the position of the stitched image because there are other sensors synchronized with the captured image, and we need to also synchronize their readings within the stitched image (i.e. we know where the reading is within each single capture, but not if captures are stitched together).
In short, given a list of images, how can we find the coordinates of each images relative to each other?
Basically while stiching correspondence between two (or more) images are setup. This is done with some constant key points. After finding those key points the images are warped or transformed & put together, i.e. stitched.
Now those key points could be set/ noted as per a global coordinate system (containing all images). Then one can get the position after stitching too.
Most of the steps are similar to panaroma stitching. You can follow this link for your problem.
Basically, one/some image(s) will be your reference image(s), and you will find the transformation between it and the other ones. These transformations will be your 4*3 homography matrices. Any point in an image can be transformed into another image's coordinate system using these matrices homography. So, you can overcome the occlusion issue that you are trying to solve. Another source for homography.
Okay so i am trying to find homography of a soccer match. What i have till now is
Read images from a folder which is basically many cropped images of a template soccer field. Basically this has images for center circle and penalty lines etc.
Read video stream from a file and crop it into many smaller segments.
Loop inside the images in video stream and inside that another loop for images that i read from folder.
Now in the two images that i get through iteration , i applied a green filter because of my assumption that field is green
Use orb to find points and then find matches.
Now the Problem is that because of players and some noise from croud, i am unable to find proper matches for homography. Also removing them is a problem because that also tends to hide the soccer field lines that i need to calculate the homography on.
Any suggestions on this is greatly appreciated. Also below are some sample code and images that i am using.
"Code being used"
Sample images
Output that i am getting
The image on right of output is a frame from video and that on left is the same sample image that i uploaded after filterGreen function as can be seen from the code.
Finally what i want is for the image to properly map to center circle so i can draw a cube in center, Somewhat similar to "This example" . Thanks in advance for helping me out.
An interesting technique to throw at this problem is RASL. It computes homographies that align stacks of related images. It does not require that you specify corresponding points on the images, but operates directly on the image pixels. It is robust against image occlusions (eg, players moving in the foreground).
I've just released a Python implementation here: https://github.com/welch/rasl
(there are also links there to the original RASL paper, MATLAB implementation, and data).
I am unsure if you'd want to crop the input images to that center circle, or if the entire frames can be aligned. Try both and see.
I am trying to extract a subimage from a scanned paper like this:
https://cloud.kopa.ch/index.php/s/gGZm5xeMYlPfU81
The extracted images should be georeferenced and added to a webmap service, but thats not the question here.
How can I get the frame / its pixel coordinates to crop the image?
I am also free in creating the "layout" (similar to the example), which means I could add markers to get the frame better after scanning it again.
The workflow is:
generate layout - print map - draw on the map - scan it - crop "map-frame" - georeferencing this frame - show it on a webmap
The "map-frames" are preprocessed and I know their location/extent
Has anybody an idea how to crop the (scanned) images automatically to this "map-frame"?
I have to work with python and have the packages PIL, pillow and imagemagick for the image processing
Thanks for you help!
If you need more information, don't hesitate to ask
Here's an example I adapted form the Pillow docs, check them out for any further processing that you might need to perform:
from Pillow import Image
Image.open("/path/to/image.jpg")
box = (100, 100, 400, 400)
region = im.crop(box)
Also, it might prove valuable to search Stack Overflow for this kind of operation, I'm sure it has been discussed earlier.
As for finding the actual rectangle to crop you'll have to do some form of image analysis. In it's simplest form, conceptually that could be something along these lines:
Applying an S-curve filter to a black-and-white representation of your image
Iterate over all of the pixels in the image
Keep track of horizontal and vertical lines that has sufficiently black pixel values.
Use this data to determine the bounding box of the portion of the image your interested in.
Depending on your needs you might want to look into some computer vision library instead, which are well optimized for this and similar tasks. The one that springs to mind is OpenCV which is I would guess is well optimized and documented, and there's a python module available as well.
there is this project am currently working on, which requires me to watermark every uploaded image. i have tried series of examples online, but they are not giving me what i really want as result
for example
i have an image A with image B watermarked on it, the two images are of the same dimensions. i applied opacity of 0.5 on image B before placing it on image A
now, i would really appreciate if anyone could help with a boolean function to check if image A has already been watermarked with image B before watermarking it.
thanks.
This depends on several factors that you'll need to provide more information for.
For instance, how complex are these images? Is there a lot of noise? Are the images that are uploaded similar in any way, or are they heterogenous? Are the watermarks always the same, or are they different?
As a general principle for extracting objects from images, you should look into processes such as color deconvolution, thresholding, and blob extraction.
In short--some sample images would go a long way...
yeah, finally found a dubious way to solve the problem, by hiding a specific text on the alpha layer of the image after watermarking it using steganography.
so on every upload, i get the image, iterate through the lowest pixels of the image's alpha layer, then compare the result to the text. if the result matches the text, definitely, the image has been watermarked.