Custom filling in matplotlib - python

I'm using matplotlib for visualizing some data on a world map, and I would like to fill the regions with a custom pattern, which may be of multiple colors.
I have two main patterns that I would like to obtain:
fill each region with stripes, but those stripes have multiple colors and different thickness depending on the region. For example, one region may be totally red, another may be half red and half green, and another may have red and blue lines, but red lines are much thicker than the blue ones.
fill with different colors in a pie-chart sliced fashion: some rays depart from the centroid of the region toward the borders,
More generally, I would like to understand how to draw a custom image and use it as a repeated pattern. Each region I've got is a set of lines, so I can assume that I can compute its centroid, size and borders before drawing the pattern.
For example, I may want to draw an histogram for each region and plot the histogram inside the region, but for doing that I need a general way for using custom images as patterns.
So, how do I do that? I tried looking at matplotlib gallery, but didn't see anything like that.
EDIT: I saw the hatch demo, but as far as I understand, has just one color, and I cannot use custom images in it http://matplotlib.org/examples/pylab_examples/hatch_demo.html

Related

Interpolating colors inside a contour in opencv [python]

I am dealing with some images which contain tables and there are 1 or 2 stickers on them. What I am trying to do is getting rid of those stickers. Using color thresholding (in HSV) and contour detection I am able to create a mask for those stickers. Now I want those stickers to "dissolve" out from there (I don't know the correct term for this). While keeping those tables lines intact, so that my line detection works well (which I have to do after this cleaning).
I tried OpenCV's inpaint. But this doesn't work well here, because the sticker size is big enough.
See this example:
Part of the whole image where the sticker is sticking (inside contents are censored by me). It can be over horizontal lines, or vertical lines, or both. Basically, it's sticking somewhere on the table (maybe over some text too, but that can't be recovered anyway). The background won't be necessary whitish, it can be pink/orange/other colors.
This is the thresholded image, creating a mask of the sticker. We can also get the contour of this if required.
This is the result of cv.inpaint() with radius 3.
What I want is to reconstruct those lines.
My solution
Now my approach is to interpolate the colors in between the sticker contour, to fill it up. For each pixel inside the contour, I will do a vertical interpolation and a horizontal interpolation (interpolation of the boundary colors) and then fill that pixel with the average of both. I am hoping that this will preserve my vertical and horizontal lines at least. (Might fail if it's on a corner of the table). This will also keep the background smooth, my background can have some different colors.
Now my problem is how I can implement this. What I have are contours that I find using OpenCV's get_contours(). I don't know how to get the colors on its boundary and how to interpolate the in-between colors.
Any help is appreciated. Thanks in advance.
Due to confidentiality, I cannot share the whole image.
EDIT
I tried the seam-carving method (implementation). Here are the results:
Vertical seaming
Horizontal seaming
It works well once I know which one to use. And I am not sure how well it will do when we have both horizontal and vertical lines.
PS. Don't suggest a solution which needs to find lines and then work. Because there will be many lines in my whole image.
You can make synthetic example images. To better explain your issue.
As I got it you can use Poisson image editing. Just take a piece of clear paper image and paste it using poisson blending and the mask you extracted.
Check this github repo as instance for examples with code.

contour plot matplotlib on a specific background color

I am generating contour plots (with transparent background) for pH of water on a river, and am overlaying the generated plot on the interactive map using map box. It looks like this:
I want to overlay plot in only on the water area, and not show over the ground area.
In my understanding there should be two ways possible:
1. While generating the image, making that part invisible
2. While overlaying the image, making that part invisible
I have tried finding solution for both but couldn't get a solution. Is there any way to go about it?

uniform shading opacity for union of regions in matplotlib

I am plotting many overlapping regions with MatPlotLib, and I would like them to not be opaque. I can reduce the opacity of each region individually by setting alpha=0.2 (or some number <1), but when the regions overlap they become quite dense and almost opaque again. Is there any way to assign the union of these regions one overall opacity? Screen shot attached -- I'd like the whole region to be as transparent as the bottommost shading, and not as dark as it gets at the top.
Thanks!
-Sam

Is there a non-manual way to change matplotlib clabel locations?

I have a matplotlib contour plot of wind speed (m/s) with contour labels using clabel. Unfortunately, the default clabel locations are poorly placed - see the top right corner:
I would like to change this to make the plot easier to read.
I understand how to manually set the contour labels from the second response to this post.
However, I have so many contours and multiple figures that it seems like a very impractical solution to do this manually. Is there a non-manual way to clean up the contour label locations? Also, could I have more than one contour label per contour without doing it manually?

How to identify stripes of different colors

how can I identify the presence or absence of regular stripes of different colors, but ranging from very very very very light pink to black inside of a scanned image (bitmap 200x200dpi 24-bit).
Carry a few examples.
Example 1
Example 2 (the lines are in all the columns except 7 in the second row of the last column)
For now try to identify (using python language) whether or not there is at least 5-10 pixels for the presence of different color from white to each strip, however, does not always work because the scanned image is not of high quality and the strip changes color very similar to color that surrounds it.
Thanks.
This looks to me a connected component labeling in an image to identify discrete regions of certain color range. You can have a look to cvBlobLib. Some pre-processing would be required to merge the pixels if there are holes or small variations between neighbors.
Not going to happen. The human visual system is far better than any image processing system, and I don't see anything in the 2nd row of #3. #1 and #5 are also debatable.
You need to find some way to increase the optical quality of your input.
Search for segmentation algorithm ,with a low threshold.
It should give you good results as the edges are sharp.
Sobel would be a good start ;)

Categories

Resources