How to obtain the difference between 2 image in Matlab? - matlab

I have 2 scatter plots obtained from an experiment. The images look very similar on a naked eye. I would like to obtain the difference between these 2 images. The 2 images have :
Same Background
Line markers are yellow and blue.
I am not an expert with image processing tools in Matlab. What would be the right approach to highlight the differences in the 2 scatter plots ?
Do we need to plot the scatter plots using the same linemarkers in order to obtain the difference ?
Thanks

You could use the command imshowpair(img1,img2) to compare between images, more help can be found at Mathworks Compare differences between images section.

Simple, in openCV, I would use absDiff which will highlight the difference very well. MatLab too have this function, while I have never used the MatLab's version before, it shouldn't differ too much from the OpenCV version.
Here's the MatLab equivalent: imabsdiff
An example showing how to utilise absdiff for your case: imabsdiff example with code
Do comment if you need anymore help, or if that doesn't solve your problem.

Related

how to produce jet color in 2d scatterplot in MATLAB?

Basically, I have been trying to create a jet colored scatter plot in MATLAB.
Ref: Clayson et al. 2013
I have no z-value. Colormap is also not working. How exactly to do it? Thanks
What you are looking for is called a density scatter plot. You don't need a third dimension in order to create it, so don't worry for your missing z. The coloring algorithm is based on the density of the points.
Such plotting function is not included in the default Matlab packages and toolboxes, but after a quick search I probably found exactly what you are looking for. Take a look at this File Exchange release. It contains a full working function for creating density scatters together with a few illustrated usage examples:

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

Matlab: How to avoid artefacts in filled contour plots

I am trying to export filled contour plots from Matlab as vector graphics to include in a Latex file. My current methodology is:
contourf(x,y,v_mag,20), axis([0,width,0,height]),daspect('manual') ;
grid off
colormap jet
h = colorbar;
caxis([0 v_lid])
h.Label.String = 'Velocity Magnitude (m/s)';
set(gcf,'renderer','painters')
export_fig('-painters', '-transparent', 'pdf', 'filename.pdf');
The problem with this method is that it produces artefacts (the white lines) which look like the following:
I understand that these white lines are the polygons defining the shaded areas which have invisible edges, and don't quite overlap (according to here). The problem is caused by the pdf viewer itself which tries to smooth the lines displayed on the screen (according to here). My problem is that most people viewing the document will not know this and will not know how to prevent the viewer doing this. So my questions is:
Is it possible to create a vector graphic of a filled contour plot from Matlab without these artefacts?
Eps produces the same problems. I have tried to use the SVG function but have not had any luck. I am trying to avoid using raster graphics due to the pixelation caused by zooming in. Any advice would be much appreciated.
EDIT - Additional info - Using Matlab v.2014b and Ghostscript v.9.15
This is an extremely frustrating issue for which there seems to be no solution (or even, few attempts at a solution), and it has been many years now. In summary, Matlab cannot cope with outputting artefact-free contour or surface plots (anything with complicated meshes or transparencies).
I can suggest a simple workaround that will work in most cases, where the colours or details of the underlying contour plot do not need to be preserved perfectly.
Output a version of the figure without lines in png format with high enough resolution.
Output a version of the figure without colours in pdf format. This should be free of any artefacts. If your figure it complicated and has many transparencies, you may need to output multiple versions building up the 'levels'.
Use Adobe Illustrator (or some equivalent) to perform a vectorized trace of the raster image. You may lose some detail here, but for simple contour plots with limited details, it will be converted easily to vectorized form.
Overlay the two images within Illustrator. Output in vector format.
This also allows you to use things like Illustrator's ability to compress pdfs.
If you don't want to toy with vectorizing the raster output, you can also simply replace steps 3-4 and combine a raster colour image with a vectorized line image. This would work well for complicated contour plots giving you crisp lines, but the ability to compress the underlying colours.
Eventually, MatLab 2013b doesn't have this problem. Furthermore the files it produces has much less volume. That is because MatLab 2013b composes vectorized image of big overlapping figures, while MatLab 2014b makes that awful meshing.
Here the first file was got with 2013b and the second with MatLab 2014b (I highlighted one of the polygons with red stroke to show the difference). The volumes differ in approximately 22 times (38 Kb vs. 844 Kb).
So it is not the viewer problem, it's how the image is exported from MatLab.
The issue is also discussed here Triangular split patches with painters renderer in MATLAB 2014b and above, but still no direct solution.

Fitting data smoothly in Matlab and Gnuplot

I would like to find a better way of fitting my data. Right now, that it the best I can do, see Figure.
It's done using Gnuplot and smooth when plotting. However, as you might see in the Figure, 'csplines' seems to be the most acuarate technique, but it is not enough. It is fine in the first half of the graph, but not good at all in the second half.
The real data, just 4 points in 'x=[1,2,4,8]', is marked in 'Line 1'. Is there a better way of doing it using Gnuplot?
What about Matlab (or even other tools)? How can I easily create a smooth curve connecting a few points?
Why not have a look at the scipy interpolation documentation:
http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
There are plenty of schemes there which will help you plot your smoothed data using matplotib.
HTH

Colouring specific points in a MATLAB surface plot

I have a 3 dimensional data set which I intend to analyse. After analysing the data set, basically running an algorithm to find a range of points, I this range of points to have a specific colour so that when someone sees the surface plot, they know which are the points of interest. How can this be achieved?
I have tried to find some help in the mathworks forums, but so far I am not able to find a satisfactory solution.
If you are using the surface function, you can use the 4 parameter version surf(x,y,z,c) where c lets you specify colour based on the currently used colour map. See this link at the mathworks site for more detail http://www.mathworks.co.uk/help/matlab/ref/surf.html