How to overlap two label to make mask for segmentation in ITK-snap? - computer-vision

I'm annotating CT scan slices(Nifti format) with ITK-snap. One slice contains two labels(Subarachnoid and Intraparenchymal) in the same area. Here is the original annotated image link: https://ibb.co/FJpyVZF
Since two labels are overlapping, the intersection area in the slice should contain both labels. But it shows it only contains the label which has been drawn last. Since the Subarachnoid area was drawn last over the Intraparenchymal area, the final segmented image only shows it contains Subarachnoid in the intersection region. I'm attaching the annotated slice https://ibb.co/F3TrXtq and segmented slice https://ibb.co/sRgdndY to clear my point.
What can I do to make the intersection area contain two labels?

ITK-SNAP uses binary label maps. That approach does not allow label overlap. Your options are:
Use a different label map for each structure you are segmenting.
Use a different segmentation representation. This will require use of different software. I recommend 3D Slicer.

Related

I have a large list of bounding boxes, how can I calculate duplicates?

I have a list of bounding boxes, I was wondering how I could calculate which ones were redundant / duplicates.
The reason being is I have 2 million of these I send to a API and I want to know which are overlapping others so I can reduce them down so each box only covers a unique area of land, so no two bounding boxes cover the same piece of geo space.
How would I calculate it so that these bounding boxes were each covering their own unique space of geo land ?
I am writing this program in C++ btw.
I think that this task is more complex then you think.
You would have to split existing boxes, untill no overlapping exists, and then remove the boxes totally contained in another.
Instead giving you a solution to that, I recomend to check if you can live with:
1) remove the boxes that are totally contained in another box.
2) leave (partly-)overlapping boxes as they are.
For 2 millions you need a spatial index (QuadTree), to get a list of all boxes nearby one box.
If you have to avoid any overlappings, then you must continue to think what should be the result?
A) A union of overlapping rectangles that therfore is not an rectangle anymore, but a polygon.
or B) The result should be rectangles.
You could check if X% of a box's vertices are inside another box to find if it's overlapped but I suppose this isn't the optimal solution.

Plotting/finding perimeter of data on a scatter plot

Regarding the included graph (It's been ListLinePlotted to show the data sets more clearly),
1: How would I find and or plot the perimeter of each data set; ideally in List form, so it will scale when I plot it using LisLogPlot alongside the original data. (Similar to FindCurvePath, but for a non-round shape)
2: How would I fill the entire area encompassed by the data set on the ListPlot. i.e. the resulting graph would have four block color areas in the shape of each region.
Essentially I'm just trying plot graphs which clearly show the different regions. If there are better ways then I'd be open to suggestions!
P.S. the regions will never intersect for this particular plot.

c++ Determine images in a polygon contour

I am using GPC (General Polygon Clipper) to create sets of images. I am unable to determine if the images are from disjoint sets though.
I am using a gpc_polygon struct defined at the above link, reading the vertex list from an image data (lat/lon of corners)... And adding images sequentially to a polygon.
It is important to separate images that belong to separate regions. While I can't say for sure that the intersection area will be non-zero (that would have been a perfect test), I have noticed that the num_contours of the completed polygon coincides with the number of distinct regions.
I thought that I can use num_contours to determine if an image belongs to a set.
Yet, as I add images, I can see, on one image, num_contours=1, after the second, it increases to 2 (whether the image is in the same section or not, and that makes sense)... but it doesn't increase after that, until the pattern of disjointed images is really off - so I can't really use it to test, at least not on its own.
It is the same as I remove images from the polygon, using a DIFF operator.
If anyone else has used GPC, or some other method of polygon convolution, perhaps you can give me some advice on what I can use to identify which images belong to each contour, so I can either separate them before, or after, polygon creation ?
I used num_contours, with a limiting value of 2 instead of 1, and had to go back iteratively, and try to re-add contours, until I couldn't add them anymore. The solution is suboptimal, may be very slow, and there are situations when polygons that don't belong together end up in the same contour.

Finding Circle Edges :

Finding Circle Edges :
Here are the two sample images that i have posted.
Need to find the edges of the circle:
Does it possible to develop one generic circle algorithm,that could find all possible circles in all scenarios ?? Like below
1. Circle may in different color ( White , Black , Gray , Red)
2. Background color may be different
3. Different in its size
http://postimage.org/image/tddhvs8c5/
http://postimage.org/image/8kdxqiiyb/
Please suggest some idea to write a algorithm that should work out on above circle
Sounds like a job for the Hough circle transform:
I have not used it myself so far, but it is included in OpenCV. Among other parameters, you can give it a minimum and maximum radius.
Here are links to documentation and a tutorial.
I'd imagine your second example picture will be very hard to detect though
You could apply an edge detection transformation to both images.
Here is what I did in Paint.NET using the outline effect:
You could test edge detect too but that requires more contrast in the images.
Another thing to take into consideration is what it exactly is that you want to detect; in the first image, do you want to detect the white ring or the disc inside. In the second image; do you want to detect the all the circles (there are many tiny ones) or just the big one(s). These requirement will influence what transformation to use and how to initialize these.
After transforming the images into versions that 'highlight' the circles you'll need an algorithm to find them.
Again, there are more options than just one. Here is a paper describing an algoritm
Searching the web for image processing circle recognition gives lots of results.
I think you will have to use a couple of different feature calculations that can be used for segmentation. I the first picture the circle is recognizeable by intensity alone so that one is easy. In the second picture it is mostly the texture that differentiates the circle edge, in that case a feature image based based on some kind of texture filter will be needed, calculating the local variance for instance will result in a scalar image that can segment out the circle. If there are other features that defines the circle in other scenarios (different colors for background foreground etc) you might need other explicit filters that give a scalar difference for those cases.
When you have scalar images where the circles stand out you can use the circular Hough transform to find the circle. Either run it for different circle sizes or modify it to detect a range of sizes.
If you know that there will be only one circle and you know the kind of noise that will be present (vertical/horizontal lines etc) an alternative approach is to design a more specific algorithm e.g. filter out the noise and find center of gravity etc.
Answer to comment:
The idea is to separate the algorithm into independent stages. I do not know how the specific algorithm you have works but presumably it could take a binary or grayscale image where high values means pixel part of circle and low values pixel not part of circle, the present algorithm also needs to give some kind of confidence value on the circle it finds. This present algorithm would then represent some stage(s) at the end of the complete algorithm. You will then have to add the first stage which is to generate feature images for all kind of input you want to handle. For the two examples it should suffice with one intensity image (simply grayscale) and one image where each pixel represents the local variance. In the color case do a color transform an use the hue value perhaps? For every input feed all feature images to the later stage, use the confidence value to select the most likely candidate. If you have other unknowns that your algorithm need as input parameters (circle size etc) just iterate over the possible values and make sure your later stages returns confidence values.

Counting objects on a grid with OpenCV

I'm relatively new to OpenCV, and I'm working on a project where I need to count the number of objects on a grid. the grid is the background of the image, and there's either an object in each space or there isn't; I need to count the number present, and I don't really know where to start. I've searched here and other places, but can't seem to find what I'm looking for. I will need to be tracking the space numbers of the grid in the future, so I will also eventually need to know whether each grid space is occupied or empty. I'm not going so far as to ask for a coded example, but does anybody know of any source or tutorials to accomplish this task or one similar to it? Thanks for your help!
Further Details: images will come from a stable-mounted camera, objects are of relatively uniform shape, but varying size and color.
I would first answer a few questions:
Will an object be completely enclosed in a grid cell? Or can it be placed on top of a grid line? (In other words, will the object hide a line from the camera?)
Will more than one object be in one cell?
Can an object occupy more than one cell? (closely related to question 1)
Given reasonable answers to those questions, I believe the problem can be broken into two parts: first, identify the centers of each grid space. To count objects, you can then sample that region to see if anything "not background" is there.
You can then assume that a grid space is defined by four strong, regularly-placed, corner features. (For the sake of discussion, I'll assume you've performed the initial image preparation as needed: histogram equalization, gaussian blur for noise reduction, etc.) From there, you might try some of OpenCV's methods for finding corners (Harris corner detector, cvGoodFeaturesToTrack, etc). It's likely that you can borrow some of the techniques found in OpenCV's square finding example (samples/c/square.c). For this task, it's probably sufficient to assume that the grid center is just the centroid of each set of "adjacent" (or sufficiently near) corners.
Alternatively, you might use the Hough transform to identify the principal horizontal and vertical lines in the image. You can then determine the intersection points to identify the extents of each grid cell. This implementation might be more challenging since inferring structure (or adjacency) from "nearby" vertices in order to find a grid center seems more difficult.