I had written a code to obtain a threshold pixel value of an image for imaging particles. I have got a plot attached below. I want to choose a point where there is sudden jump in the value. This will be my threshold value. I can manually do this by seeing the point. But I want to do it automatically through code what should I do?
I was thinking of sorting it and finding frequency. Then loop it to compare it with previous value. I want to know what should I choose the minimum difference to between these two values.
What other method should I use?
Here is the Image:
Firstly, what do you mean by "sudden jump"? If I understand well, it means that there is a big difference (descrease) of pixel numbers between two adjecent gray levels. Then you can just right shift the histogram vector, and substract the two vectors, getting a vector containing the differences between two adjacent gray levels. And then, you can choose a threshold. That's all.
Related
I have two binary images, each of which have a single white filled parallelogram and a black background. The only difference between the two images is that the parallelograms are in different locations and are slightly different from one another in shape. All the parameters between the two images are the same except for that one change.
I want to check how similar the shape of the two parallelograms are, by using some sort of comparing measure.
I looked into ssimval function in MATLAB but it seems to be taking the whole image into consideration rather than just the white blobs. Is there any other function I can use for this purpose?
For visually checking similarity, you can plot their probability density function and for numeric similarity, compute some similarity measure, such as, KL Divergence, etc.
In a simple way, you can segment your binary image with simple bwlabel function. Then use regionprops function to find perimeter and area of your desire segment. Moreover, center of region is also another comparison point.
You could do it with polygons, by using the polyshape class.
First convert the binary mask to a set of corner points. You can do it with a convex hull, by calling regionprops(bwI, 'ConvexHull').
Then convert the corner points into polygons, by calling polyshape.
Finally measure the dissimiliarities of the polygons by measuring their turning distance. Turning distance is rotation- and scaling invariant, so you might want to add additive terms to your distance metric for those if your problem demands it.
A very simple solution for comparing two binary image is using boolean operations.
Your images contains zero and one values. so If you use boolean operation.
suppose your two images are : B1 , B2
C = B1 & (~B2)
if sum(C(:))==0
% two image are same
else
% two image are different
end
I'm trying to calculate and present the Subtraction images of a Dynamic MRI Sequence. However, I've looked for quite some time and I can't seem to find how to relate the individual Rescale Slope and Intercept and even Window Center and Width fields with the respective fields for the new Subtracted image.
I'm sorry if it is a repost but I can't find the answer for this particular problem.
I guess that for Slope and Intercept I probably should just apply the old ones, subtract the images and make sure they are within uint16 range, but what about Window Center and Width?
Thanks in advance
About Rescale Slope and -Intercept:
You can apply the original values of the slices you subtracted, if they are all equal in the slices you subtract from each other. If they are not equal, you will have to rescale one of the slices to the slope/intercept of the other one before doing the subtraction. Otherwise, the subtraction will yield wrong grayscales. Obviously, the resulting subtracted image will then be assigned the slope and intercept of the slice you rescaled the other one to.
About Window Center and -Width:
There is no answer which is right or wrong. Windowing depends on the taste of the person viewing the images - ask three physicians and receive four different answers ;-)
I would rather recommend to calculate new values from the histogram of the subtracted image than trying to calculate them from the orginal slices. Subtraction means that you eliminate tissue. The original values were probably adjusted in such a way that this tissue is visible. Now that you have subtracted it you want to have a window that emphasizes the vessels - the rest is just noise.
I am trying to erode objects in a binary image such that they do not become smaller than some fixed size. Consider, for instance, a binary map composed of connected components (blobs), wherein one defines blob size by either the minimal or maximal antipolar (anti-perimetric) distance (i.e., the distance between two points that are as far from one another as they can be on the perimeter or contour of the blob; if the contour consists of N consecutively numbered points, then the distances evaluated would be those between points 1 and N/2+1, points 2 and N/2+2, etc.). Given such an arrangement, I seek to erode these blobs until the distance metric reaches a specified limit. If the blobs were simple circles, then the effect could be realized by ultimate erosion followed by dilation to a fixed size; however, the contour of an irregular object would be lost by such a procedure. Is there a way to achieve such an effect for connected, irregular components using built-in functions in MATLAB?
With no image and already tried code presented I can understand you wrong, but may be iterative using bwmorph with 'thin','skel' or 'shrink' will help you.
while(cond < cond_threshold)
bw=bwmorph(bw,...,1); %one of the options above
cond = calc_cond(bw);
end
need some help here on image processing. I'm using Matlab and try to segment the following figure based on the two major peaks (in yellow). The color yellow means higher value and blue means low value (on z-axis, or image color from 0 to 1 for your convenience). The ideal cut is roughly the line from point (1,75) to (120,105). But I want a systematic way to derive this rather than by observation.
My intuition was to first identify the two peaks (based on this), and then classify each point/pixel on this figure to the two peaks (the metric here is to compute the shortest Euclidean distance to the edge of the two peaks).
And I end up with the following fig.
As you can see, the cut is pretty much a straight line, which I'm not quite satisfied. Maybe I can use the orientation of the peak circle and somehow tilt the line.. but I'm not sure how to do so? Any clues? Thanks.
This is an Image segmentation problem.
you can use GMM Gaussian of Mixture Model to model the image.
in your case the number of components will be 2.
after you model the image by using this mixture, you can find the probability of each pixel P(pixel x belong to the first component or the second component)
check
http://www.mathworks.com/matlabcentral/newsreader/view_thread/272162
http://www.mathworks.com/help/stats/cluster-data-from-mixture-of-gaussian-distributions.html
So, this is going to be pretty hard for me to explain, or try to detail out since I only think I know what I'm asking, but I could be asking it with bad wording, so please bear with me and ask questions if need-be.
Currently I have a 3D vector field that's being plotted which corresponds to 40 levels of wind vectors in a 3D space (obviously). These are plotted in 3D levels and then stacked on top of each other using a dummy altitude for now (we're debating how to go about pressure altitude conversion most accurately--not to worry here). The goal is to start at a point within the vector space, modeling that point as a particle that can experience physics, and iteratively go through the vector field reacting to the forces, thus creating a trajectory of sorts through the vector field.
Currently what I'm trying to do is whip up code that would allow me to to start a point within this field and calculate the forces that the particle would feel at that point and then establish a resultant force vector that would indicate the next path of movement throughout the vector space.
Right now I'm stuck in the theoretical aspects of the code, as I'm trying to think through how the particle would feel vectors at a distance.
Any suggestions on ways to attack this problem within MatLab or relevant equations to use?
In order to run my code, you'll need read_grib.r4 and to compile that mex file here is a link to a zip with the code and the required files.
https://www.dropbox.com/s/uodvixdff764frq/WindSim_StackOverflow_Files.zip
I would try to interpolate the wind vector from the adjecent ones. You seem to have a regular grid, that should be no problem. (You can use interp3 for this)
Afterwards, you can use any differential-equation solver for your problem, as you have basically a field of gradients and an initial value. Forward euler would be the simplest one but need a small step size. (N.B.: Your field should be a gradient field)
You may read about this in Wikipedia: http://en.wikipedia.org/wiki/Vector_field#Flow_curves
In response to comment #1:
Yes. In a regular grid, any (arbitrary chosen) point will have eight neighbors. interp3 will so a trilinear interpolation to determine an interpolated gradient vector.
If you use forward-euler, you will then move a small distance in that direction. There you interpolate a gradient and go a small step into this new direction and so on. What happens are two things:
You get a series of points that lie on a streamline and thus form the trajectory of a particle moving along the field
Get large errors, the further you move and the larger the step size is. Use a small step size or use a better solver (Runge-Kutta comes to my mind)
If all you want is plotting, then the streamline function might help.