Apply CIFilter on a region of interest - core-image

Is it possible to apply a filter only on a region of interest or do I have to apply each filter on the whole image?
How to apply a filter on a defined region of interest? For example a selected rect/circle inside the input image?
How do I apply a filter on all pixel values deviate from a set RGB pixel by a fixed tolerance?

Related

Getting a specific contour in VTK

I like to get a specific contour from image data.
My main goal is to remesh a polydata in grid form. So I followed below pipeline:
convert polydata to image using PolyDataToImageData
convert above image output to vtkImageDataGeometryFilter
use vtkImplicitPolyDataDistance to compute the distance from the original polydata
copy the distance values to image output scalars in step 2
The result is below:
I then tried to use vtkContourFilter to get polydata with SetValue(0, 0.0). And as you can see the result is not entirely correct:
The value of distance array is https://pastebin.ubuntu.com/p/2mZsgdrcmX/ and it is never 0 so I think I am doing it wrong in SetValue but I am also not sure how to get that specific green contour.
Is there any way to get those green points contour?
I am not completely sure to understand your pipeline.
In the vtkContourFilter, the SetValue takes two parameters. The first one is the id of the contour (as the filter can extract several contours at once, see the SetNumberOfContours). The second is the isovalue of the contour.
Here, you set an isovalue of 0.0. Which means you want the points at a distance 0 of the original data set. Looking at the first image, it seems these are the red points. If you want a contour at the green points, you may want to specify a higher scalar value.
PS: If the goal of your pipeline is to have a "larger version" of your shape, you may also have a look at the vtkWarpVector (and give it the normals of your polydata).

Spotfire 3D plot

I plotted a 3D wellbore using surveys. I would like to color the horizontal sections of the wellbore based on certain fracture depths. I have two additional columns that have these fracture depths. Is there a way to use custom expression to color my 3d wellbore using these two columns, for example: if([measured.depth]>[upper.perf] and ([measured.depth]<[lower.perf])), then color Axis.measured.depth(blue). Hope that makes sense. Thank you
probably the most straightforward and "correct" way to do this is to create a new Calculated Column (Insert ยป Calculated Column). here you can build an expression that will be used later to define colors. based on the info you provided, that expression could look like:
If([Measured Depth (ft)] > [Frac Lower Perf] AND [Measured Depth (ft)] < [Frac Upper Perf])
this will return True for values outside of [Frac Upper Perf] and [Frac
Lower Perf] and False otherwise. you can make these labels a bit more informational ("Inside"/"Outside" maybe?) by modifying the If() statement (see the documentation for details)
if you open up the visualization properties, then go to the Colors page, you have options for the Color By Columns. choose the column we just created. change the Color Mode to Unique Values and choose your color for the true and false values.

how to choose a range for filtering points by RGB color?

I have an image and I am picking colors by RGB (data sampling). I select N points from a specific region in the image which has the "same" color. By "same" I mean, that part of the image belongs to an object, (let's say a yellow object). Each picked point in the RGB case has three values [R,G,B]. For example: [120,150,225]. And the maximum and minimum for each field are 255 and 0 respectively.
Let's assume that I picked N points from the region of the object in the image. The points obviously have different RGB values but from the same family (a gradient of the specific color).
Question:
I want to find a range for each RGB field that when I apply a color filter on the image the pixels related to that specific object remain (to be considered as inliers). Is it correct to find the maximum and minimum from the sampled points and consider them as the filter range? For example if the max and min of the field R are 120 ,170 respectively, can it be used as a the range that should be kept.
In my opinion, the idea is not true. Because when choosing the max and min of a set of sampled data some points will be out of that range and also there will be some point on the object that doesn't fit in this range.
What is a better solution to include more points as inliers?
If anybody needs to see collected data samples, please let me know.
I am not sure I fully grasp what you are asking for, but in my opinion filtering in RGB is not the way to go. You should use a different color space than RGB if you want to compare pixels of similar color. RGB is good for representing colors on a screen, but you actually want to look at the hue, saturation and intensity (lightness, or luminance) for analysing visible similarities in colors.
For example, you should convert your pixels to HSI or HSL color space first, then compare the different parameters you get. At that point, it is more natural to compare the resulting hue in a hue range, saturation in a saturation range, and so on.
Go here for further information on how to convert to and from RGB.
What happens here is that you implicitly try to reinvent either color indexing or histogram back-projection. You call it color filter but it is better to focus on probabilities than on colors and color spaces. Colors of course not super reliable and change with lighting (though hue tends to stay the same given non-colored illumination) that's why some color spaces are better than others. You can handle this separately but it seems that you are more interested in the principles of calculating "filtering operation" that will do segmentation of the foreground object from background. Hopefully.
In short, a histogram back-projection works by first creating a histogram for R, G, B within object area and then back-projecting them into the image in the following way. For each pixel in the image find its bin in the histogram, calculate its relative weight (probability) given overall sum of the bins and put this probability into the image. In such a way each pixel would have probability that it belongs to the object. You can improve it by dividing with probability of background if you want to model background too.
The result will be messy but somewhat resemble an object segment plus some background noise. It has to be cleaned and then reconnected into object using separate methods such as connected components, grab cut, morphological operation, blur, etc.

Change pixels color [duplicate]

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.

JFreechart color square grid on XY plot

Is it possible to assign different colors to different grid squares on an XYplot in jfreechart?
I have a chart whose grids I want to assign different values and want to assign colors based on these values
Thanks
How this can be done on an XYSeriesCollection for XYSeries?
Yes, among the JFreeChart Samples, XYTaskDatasetDemo2 and XYBlockChartDemo[1-3] are examples.

Resources