I wish to fill the hollow masks in the below binary image. I tried finding contours to fill but didn't work.
Can someone give me some pointers on How to do it?
If you found the contours, they you can just fill the convex poly.
cv2.fillConvexPoly(binary_image, np.array(rect['boundary'], 'int32'), 255)
You will have to adjust this line to work with your own code, but just pass it an index to the contour that you want to fill, and it will fill it with your desired color.
Related
My question is about color tracking... What is the color threshold value for white in python ? I need to track the white color alone in a group of pictures. So I need to separate the white color. In order to do so I need to know the threshold value of white color...
It depends on your pictures. Assuming that you're going to threshold using the RGB values, the RGB value for white is (255, 255, 255). But this value holds true for pure white color. If you have real-world pictures, you might have clearly white color at certain areas in your image but they wouldn't have the value (225, 255, 255). Factors like the shadow, lighting conditions, angle etc. contribute to the variance from pure white color value.
In order to threshold correctly, you need to check the range of values for your set of pictures. I recently worked on a similar problem and for my case, the range of values was as follows:
Red channel: 200-255
Green channel: 180-255
Blue channel: 140-255
But please note that this accepts a lot of variation of white like light yellow. It will highly depend on your case so make sure you check the range on your data.
One way of that can be by displaying/showing your image using skimage and then hovering over white areas, it will display the RGB value on the bottom right corner of the image. Here is the code for showing an image in skimage:
from skimage import io
def show(img):
io.imshow(img)
io.show()
You can create a range of values/threshold from the values you notice this way.
I am trying to give some border to my cross text which around 45 degree in excel but issue is that whenever i apply border to cross text the border also get apply at 45 degree.
I am looking for a straight rectangle border which contains cross text in it in excel.
Please help me to do that
I dont think you can find a way around that, but you could improvise;
try removing all the borders on that particular cell then sort of draw a rectangle (Or similar shape) and set its fill to nothing so it can give this impression of a "straight border" and this will look good, if you format it well that is, on printed paper.
Or you can draw a textbox on top of the cell (with the same size) and remove any color fill
If there's an option of locking its position, it would be useful too
OK, I think this is probably simple but I've searched extensively and can't find anything. What I want to do is specify the precise RGB colour values of a contour line generated with matplotlib. I know that if I do something like :
plt.contour(X,Y,Z,[0.1,0.2,0.3],colors='k')
then I'll get three contour levels which are all black, or if I were to substitute 'w' in place of 'k' then the contours would all be white. That's fine, but what I need to do is something like this :
plt.contour(X,Y,Z,[0.1,0.2,0.3],colors=(1.0,0.25,0.75)
Where the colours not chosen from some in-built presets but have RGB (or RGBA) values precisely defined by me.
Any ideas ?
You should give a list with colors. If the list is 1 color long, it will use that color for all contours.
plt.contour(X, Y, Z, [0.1,0.2,0.3], colors = [(1.0,0.25,0.75)])
I have more then 1 week reading about selective color change of an image. It meand selcting a color from a color picker and then select a part of image in which I want to change the color and apply the changing of color form original color to color of color picker.
E.g. if I select a blue color in color picker and I also select a red part in the image I should be able to change red color to blue color in all the image.
Another example. If I have an image with red apples and oranges and if I select an apple on the image and a blue color in the color picket, then all apples should be changing the color from red to blue.
I have some ideas but of course I need something more concrete on how to do this
Thank you for reading
As a starting point, consider clustering the colors of your image. If you don't know how many clusters you want, then you will need methods to determine whether to merge or not two given clusters. For the moment, let us suppose that we know that number. For example, given the following image at left, I mapped its colors to 3 clusters, which have the mean colors as shown in the middle, and representing each cluster by its mean color gives the figure at right.
With the output at right, now what you need is a method to replace colors. Suppose the user clicks (a single point) somewhere in your image, then you know the positions in the original image that you will need to modify. For the next image, the user (me) clicked on a point that is contained by the "orange" cluster. Then he clicked on some blue hue. From that, you make a mask representing the points in the "orange" cluster and play with that. I considered a simple gaussian filter followed by a flat dilation 3x5. Then you replace the hues in the original image according to the produced mask (after the low pass filtering, the values on it are also considered as a alpha value for compositing the images).
Not perfect at all, but you could have a better clustering than me and also a much-less-primitive color replacement method. I intentionally skipped the details about clustering method, color space, and others, because I used only basic k-means on RGB without any pre-processing of the input. So you can consider the results above as a baseline for anything else you can do.
Given the image, a selected color, and a target new color - you can't do much that isn't ugly. You also need a range, some amount of variation in color, so you can say one pixel's color is "close enough" while another is clearly "different".
First step of processing: You create a mask image, which is grayscale and varying from 0.0 to 1.0 (or from zero to some maximum value we'll treat as 1.0), and the same size as the input image. For each input pixel, test if its color is sufficiently near the selected color. If it's "the same" or "close enough" put 1.0 in the mask. If it's different, put 0.0. If is sorta borderline, put an in-between value. Exactly how to do this depends on the details of the image.
This might work best in LAB space, and testing for sameness according to the angle of the A,B coordinates relative to their origin.
Once you have the mask, put it aside. Now color-transform the whole image. This might be best done in HSV space. Don't touch the V channel. Add a constant to S, modulo 360deg (or mod 256, if S is stored as bytes) and multiply S by a constant chosen so that the coordinates in HSV corresponding to the selected color is moved to the HSV coordinates for the target color. Convert the transformed S and H, with the unchanged L, back to RGB.
Finally, use the mask to blend the original image with the color-transformed one. Apply this to each channel - red, green, blue:
output = (1-mask)*original + mask*transformed
If you're doing it all in byte arrays, 0 is 0.0 and 255 is 1.0, and be careful of overflow and signed/unsigned problems.
I'm trying to figure out how to stop LinearGradientBrush to repeat along with shape I'm drawing. So, for example I created gradient with height equal to 50, but next I draw rectangle with height equal to 150. In that case gradient will repeat itself three times. But I'd like to draw only first gradient and draw nothing for the rest of rectangle.
Seems GradientBrush in WPF supports SpreadMethod(http://msdn.microsoft.com/en-us/library/system.windows.media.gradientbrush.spreadmethod.aspx) for this purpose, but does something exists for WinForms as well?
Paul, I think the easiest way may be to create your fill the same way, but only draw using a rect of 50 pixels. If you need to fill the other 100 pixels with a specific color, then do a solid fill with that color first.
Alternatively, you can try to set a blend in your gradient fill (LinearGradientbrush::SetBlend), but that seems like a lot of effort to achieve the same effect.