My question is simple.
I have a large binary image, and I would like to fill the holes in the objects. Iv'e tried using binary_fill_holes, but since the image is so big, I have to tile it, so only a small part of the image is loaded into a numpy array at a time. Therefore holes may be divided over several tiles, and are not filled by binary_fill_holes.
Here is an example of one of the tiles:
The white is the object, and all the black pixels are actually part of a hole that is also present in some of the neighbouring tiles. However, in this single tile it does not look like a hole, and is therefore not filled by the function.
I think maybe something with connected components could be used, but it gets the same tiling issues, and I am hoping there may be some easy, pythonic way.
Related
I'm very new to image processing in Python (and not massively adept at python in general), so forgive me for how stupid this may sound. Im working with an AI for object detection, and need to submit 1000x1000 pixel images to it, that have been divided up from larger images of varying lengths and widths (not necessarily divisible, but I have a way of padding out images less than 1000x1000). In order for this to work, I need 200 pixel overlap on each segment or the AI will pick may miss objects.
I've tried a host of methods, and have either got the image to divide up using the methods suggested in Creating image tiles (m*n) of original image using Python and Numpy and how can I split a large image into small pieces in python (plus a few others that effectively do the same techniques in different words. I've been able to make a grid and get the tile names from this, using How to determine coordinate of grid elements of an image, however have not been able to get overlap to work in this, as I would then just tile it normally.
Basically what I'm saying is that I've found one way to cut the images up that works, and one way to get the tile coordinates, but I am utterly failing at putting it all together. Does anyone have any advice on what to do here?
So far I've not found a direct approach to my end goal online - and I've tried mucking around with different scripts (like the ones listed above), but feel like Im barking up totally the wrong tree.
Here presented is a screenshot from a 2D game:
(Sorry, don't have the reputation to post inline images)
You can walk on the grass, the asphalt, sidewalk etc. but you cannot walk into buildings/walls/any structures. Here is a small gif to demonstrate this
What I want: my ideal goal is to create a boolean matrix, where 0 means you can't traverse through that pixel and 1 means you can. So, in this example, it would look something like this (I forgot to add the trees)
Where the "red zones" would be 0 in this array and the other tiles would be 1
What I've tried and what I had in mind:
All of my ideas lead to one thing, and I don't know if it's right: creating one universal list of "accepted" colors where we could set the pixel to be set to 1 if it's in that list of acceptable colors. This of course has its downsides: one of them being that a non-traversable territory could easily have a color of a traversable one (for example if we're using green as in the color of grass - that could be swamp or bushes), and the other downside is computation time to compare each pixel.
I've considered thresholds but if I got it correctly, it's only used for white and black comparisons.
I've also looked at image quantization using PIL, but the quantized image didn't change much for me. What would I do after the quantization?
If we look deeper into this game, a tile here is considered a 32x32 pixel area and it's drawn using a tileset (sort of a canvas): https://i.imgur.com/j9CNQdi.png and there is a list of "non-traversable" tiles (blocking), maybe it's somehow possible to use it?
Anyways, I'm lost at what to look for. I've been researching but found nothing similar. I would appreciate any advice on where to look, thanks.
I am quite new to OpenCV and DIP in general so I need bit of help in stitching of two images. The problem background is, there are two pieces which have their adhesives/glue torn apart from two joined pieces of plastic. This is the image of "glue" on the base:
and this is the image of "glue" on the other attached face:
As the background of the the images is not the same, I read that it's not possible to do stitching (because different features). And these two pieces are like jigsaw pieces which needs to rotated, so the problem is not straightforward like panaroma stitching.
How do I join such images together?
I was thinking of finding the white color countours and then keeping one image fixed, rotating the other one and finding area of merged countours, also storing the angle of what I rotate. The area would become smallest when there would be perfect match.
This is not a complete answer, (no-one said answers have to be complete), but it may inspire you or someone else to work out a method.
I flipped vertically and flopped horizontally one of your images and then put them both into Photoshop on two separate layers. I then set the "Blending Mode" to Difference which is always a great way to align images - because they normally go black when images are aligned and there is no difference.
I then moved one layer around on the other. I guess you will need to do something similar to solve your problem - you just need to find something that your code can maximise or minimise.
My question is rather about feasibility of a task.
Note that I have read the solution of this question, however you can guess I am not dealing with rectangles and cameras here.
Situation:
I need to save lot of pictures in a folder all of them obeying to these rules:
In each picture, there is ONLY one object.
The object can be anything (car, horse, human hand ...)
The size and the format of the picture belong to certain set.
The background of the object is ALWAYS white.
The color of the object itself can be anything else (including, why not, areas of white pixels)
Goal:
I want to detect if the object of each image is CENTERED.
Development environment:
Python
OpenCV
Do you think this is feasible ?
I hope my question is not too broad. I just ask if this can be done automatically without human intervention on the pictures. I have thousands of them. The program will save in a separate folder pictures in which the object is not centered.
EDIT:
Following the comments and answer above: for me, a centered object is the one if I draw a square or rectangle around it, the edges of the square/rectangle must be equivalently distant from let and right sides of the image, whereas the top and the bottom of the object must be equivalently distant from the top and bottom of the picture.
Yep this is very feasible. However, depending on the type of objects the images contain, they are different ways to accomplish this. Assuming the objects in the images all have a uniform color you can easily perform a color detection algorithm, find the centre point of the object in terms of pixels and find it's position using the image resolution as the reference.
As the background is always white as specified, this is probably your best method as you can just extract all the non white (Or different shade of white) objects within the image.
if you do decide to go with this approach, i should be able to point you to some relevant code
Although writing in c++, more information on this can be found in the link below.
http://opencv-srf.blogspot.co.uk/2010/09/object-detection-using-color-seperation.html
the link is based on object detection in a video but as a video is just a series images the same concept can be used on images
I'm making Tetris and im trying to make a line clear function. I have a way to do this that is a bit complicated and im looking to simplify.
My idea is to check some pixel RGB values and see if they're not black (the color of the background). Is there a quick way to get the RGB value of a pixel on the screen?
pygame.PixelArray should do the trick. You can use it on the screen surface.
But personally, I wouldn't recommend that you use the pixels as a reference.
Handling everything logically is a lot better.
As Icfseth noted "Handling everything logically is a lot better."
Tetris is an array of blocks that occupy a logical space that has a granularity larger than a pixel. Your game model should operate in "block coordinates" and detect whether a space is open or filled based on that. The screen is just a representation or "view" of the block space.
Try first just moving a 16px square around a 320x320px screen in steps of 16px. You could keep track of every pixel, but it makes much more sense to have have the block position ranging from x = [0..20], y = [0..20], and let the display code worry about how to show a block at position (2,3).