Rotating a heat map from a matrix in gnuplot - matrix

I'm trying to rotate 45ยบ a heat map coming from a matrix. The problem when rotating the discrete data is that the plot exceeds the window's size, reaching labels and tics place. Any idea or alternative to solve the problem?
Main code
set xrange[-20:20]
set yrange[30:50]
plot "test.txt" u ($2-$1+1):($2+$1):3 matrix with image notitle
And what I
obtain. The data file http://www.filedropper.com/test_146

I would suggest an alternative using splot with pm3d because the set pm3d has the option clip1in and clip4in which tells gnulpot which qudrangles to plot, but is available:
set pm3d map clip4in corners2col c1
set yrange[10:*]
splot 'test.txt' u ($2-$1+1):($2+$1):3 matrix with pm3d notitle
It will show some spurious triangles:
If you want to go for an interpolation, have a look at this question
Pay attention that splot [...] with pm3d will draw the colors of the quadrangles, so that if your matrix s NxM, you'll get (N-1)x(M-1). On the other hand using plot [...] with image you'll get NxM quandrangles. (see help image).

Related

Plot contour plot with label but witout dots

I have to plot contour plots in gnuplot with labels but without dots. I tried several steps to avoid dots in my plot. I want my plot with contour values in plot. For that I used splot with labels. But gnuplot plots dots in plot. how this can be avoided.
splot 'DM_Plot.txt' using 1:($2/1000):3,'DM_Plot.txt' using 1:($2/1000):3 with labels
I think we need to see more of the command sequence. It is not obvious that the dots visible in your figure come from the "splot" command. "set grid dashtype '.'" could produce such a thing. Do you have a "set grid" command?
I would guess that the sequence of commands you need is something like
unset grid
set pm3d explicit
set contours
splot 'DM_Plot.txt' using 1:($2/1000):3 with pm3d, \
'DM_Plot.txt' using 1:($2/1000):3 with labels
Does that match what you tried?

What is the easiest way to recognize colors from an image?

I want to make a program that solves the Rubik's cube.
Basically, I want the easiest way to get an output like this:
G G Y
W W Y
B G G
From an image like this:
.
Using only colors for the recognition is a very problematic because the colors are very sensitive to change in the light of the scene. Therefor if you insist on using only color i would do the following:
Take several images
For each image identify the colors and sample them.
Use the White rectangle to do white balancing.
Correct the sampled colors according to the white balancing.
For a new image first do white balancing second use the sampled values to segment the image according to each color.
My suggestion is use also the shape of the rectangles and not only the color for the segmentation.

gnuplot: plotting contour without labels works, with labels no

i am trying to plot a contour from a gridded data file called 'sample'. This script works fine for me:
set xrange[1:1e2]; set yrange[1:1e2]; set log;
set view map; unset surface
set style textbox opaque margins 0.5, 0.5 noborder
set contour base
set cntrlabel format '%5.3g' font ',7'
set cntrparam levels discrete 1e40,1e42,1e44
splot 'sample' u ($1*1e27):($2*1e18):3 wl
it plots a 2D plot with contour lines. All fine.
If i only dare to continue the plotting line with
'' u ($1*1e27):($2*1e18):3 with labels boxed notitle
to add labels to the contour lines, it takes around 15 minutes to produce a blank plot. Using gnuplot examples on sourceforge, it works.
Have you ever experienced something similar?
Many thanks in advance

Shifting Output Image Down Gnuplot

I am typing this in textedit and load it into gnuplot later. When I do so the image is slightly off the top of the screen which means I can't see some of it. Is there a way to shift the entirety of the imaged produced down, or start the z-axis lower on the image?
Also, how do I make either my points or my lines black? Currently the lines for my sphere are red and the points are blue.
set pointsize 2
set tics
set border
unset key
set size ratio -1
set size square
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
# linetype linewidth
set xrange[-1.2:1.2]
set yrange[-1.2:1.2]
set zrange[-1.2:1.2]
set view equal xyz
set xyplane at -1.2
set parametric
set isosamples 20
set hidden3d
set urange [0:2.0*pi]
set vrange [-pi/2:pi/2]
r=1.0;
# Parametric functions for the sphere
fx(v,u) = r*cos(v)*cos(u)
fy(v,u) = r*cos(v)*sin(u)
fz(v) = r*sin(v)
splot fx(v,u),fy(v,u),fz(v),"mypoints" u 1:2:3 w p 3
Thanks, A.
I shall try the transformation thing, but to try to explain my issue further just have a look at these pictures.
The first is what I get out when I run the code (now I have made everything black). The second is the same picture, but rotated (just by click, holding and moving the mouse around). As you can see on rotation the picture is off the screen. I just want the picture to be in the centre of the screen, I can't think why it wouldn't be.
Also why is there 1 or 1.5 of the z axis below the image? I don't really want that there either. Is there a way to set scales on x,y, and z axes equal? the set square thing has done it for x and y but as you can see the sphere is squished as well.
Thanks, A.
http://tinypic.com/view.php?pic=k59gx&s=6
http://tinypic.com/view.php?pic=2v9eo93&s=6
Note: I couldn't upload an image due to lack of rep, but I thought it would be the best way to illustrate my issue. The links show the images I am talking about.
Running your script, omitting the reference to "mypoints", I get the plot you want without any extra z-axis or the top getting cut off. I'm using gnuplot v.4.4.3. What version are you using? Have you tried it without also plotting "mypoints"? There might be something in there affecting the plot. Also, you might want to explore coordinate mapping (try "help mapping" at the prompt) to plot datafiles in spherical coordinates.
Ok, so basically there are loads of issues that need solving so here goes:
1) Don't shift the picture down, get rid of the little tag end from the z part of the border. This makes the picture more central.
To do this: set ticslevel 0.0
2) Aspect ratio is not maintained in X11 so it looks all squashed. This is spoken about here:
http://sourceforge.net/tracker/index.php?func=detail&aid=3331162&group_id=2055&atid=102055
The workaround as they say is to set the size of window that X11 outputs to to be square, to do this: set terminal x11 size 800,800
3) Note, you don't now need: set xyplane at -1.2 (or what ever z value you want) as this is taken care of using the set ticslevel command.
So now I have this:
set pointsize 2
set tics nomirror
set ticslevel 0.0
set border
set view equal xyz
unset key
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
# linetype linewidth
set xrange[-1.2:1.2]
set yrange[-1.2:1.2]
set zrange[-1.2:1.2]
set parametric
set isosamples 20
unset hidden3d
set urange [0:2.0*pi]
set vrange [-pi/2:pi/2]
r=1.0;
# Parametric functions for the sphere
fx(v,u) = r*cos(v)*cos(u)
fy(v,u) = r*cos(v)*sin(u)
fz(v) = r*sin(v)
splot fx(v,u) w lines lc rgb "black",fy(v,u) w lines lc rgb "black",fz(v) w lines lc rgb "black","mypoints" u 1:2:3 w points lc rgb "red" p 2
Hope this helps people in future.

Find the edges of image and crop it in MATLAB

I have a RGB image. I have scanned the image. So the image occupies a small portion of an A4 size sheet.
I want to find the border of the image and crop it. I could use edge detection operators like 'Sobel' etc, but they detect all the edges present in the image. All I want is the border of the image. Also many of the edge detection functions including 'bwboundaries' work only with binary or grayscale images. My image is RGB.
I tried using 'imcrop', but this is more of interactive cropping. I am keen on doing this automatically.
Uploading a test image:
Since this is an rgb image, there will be apparent color in the gray areas, but there should be none in the white ones. You can make use of this to find the image, then you can get the bounding box.
img = imread('http://i.stack.imgur.com/dEawA.jpg');
%# instead of "==" you can check for similarity within a tolerance
tt=img(:,:,1)==img(:,:,2) & img(:,:,2) == img(:,:,3);
%# invert tt so that it's 1 where there is signal
tt = ~tt;
%# clean up some of the smaller artifacts
tto = imopen(~tt,strel('square',100));
%# get the areas and bounding box of the areas above threshold
%# as an additional criterion, you could also use excentricity
%# or you could simply remove the bottom 100 rows of the scan
stats = regionprops(tto,'BoundingBox','Area');
area = cat(1,stats.Area);
[~,maxAreaIdx] = max(Area);
bb = round(stats(maxAreaIdx).BoundingBox);
%# note that regionprops switches x and y (it's a long story)
croppedImage = img(bb(2):bb(2)+bb(4),bb(1):bb(1)+bb(3),:);
There is a bit of a border left due to rotation. You can use the mask tto above to set all non-image pixels to NaN before cropping, or you can use imrotate to fix your image.
You can try to detect the corners of your image using e.g. the Harris-Detector (corner in Matlab). Set the maximum number of corners to detect to 4. Then use the positions of the corners in imcrop. If you would post an image I could give you more specific hints. Your image being RGB shouldn't be a problem, just convert it to grayscale.
You can try using bwlabel http://www.mathworks.com/help/toolbox/images/ref/bwlabel.html (along with find, as noted in the help page) to get the indices of the image and use those to crop the original.
You'll first need to convert the original image to binary using im2bw http://www.mathworks.com/help/toolbox/images/ref/im2bw.html.

Resources