Why ploting data in ILNumerics produce the result that is not symmetry? (2D Plot) - matlab

I have ILNumerics code like this:
var scene = new ILScene();
ILColormap cm = new ILColormap(Colormaps.Hot);
ILArray<float> data = cm.Data;
data[":;0"] = ILMath.pow(data[":;0"], 3.0f);
cm.Data = data;
ILArray<float> contoh = ILMath.zeros<float>(15, 15);
contoh[7, 14] = 1;
scene.Add(
new ILPlotCube(twoDMode: false){
new ILSurface(contoh){
Wireframe = { Color = Color.FromArgb(50, Color.LightGray)},
Colormap = new ILColormap(data),
Children = { new ILColorbar()}
}
}
);
ilPanel1.Scene = scene;
Roughly speak, I want to plot 2D model. In that matrix "contoh", I have one value that different with other neighbors. I want to plot that matrix become something like this figure:
But, there is that I got:
If we see the white area, it is not symmetry. Why this is happen? When I slightly rotate the model, we can see more clearly that even I have data in [14,7] position, the white area stretching until [13,6] but not to [13,8].
And for the last. Can anyone teach me how to make code that will generate a figure as like as Figure 1?

Both plots are different because they are of different type. The matlab one is an imagesc, the ILNumerics one is a surface. Imagesc plots will be available for ILNumerics with the next release.

Related

Plotting 3D Scatter plots in Flutter

I am looking for a flutter package to plot a 3D scatter shart given a series of X, Y, Z and R, G, B values. Looking to output something like this: https://photos.app.goo.gl/VtwTxnqHY4ahc24u6
I know echarts can do 3d scatter plots, but I need it to work on Mobile and Web
Question: does anyone know of a flutter package that I can use to plot 3d scatter charts for mobile and web?
If there is a will there is a way,
I don't know any packages but you can implement it yourself pretty easily:
1: Import the package vector_math64
import 'package:vector_math/vector_math_64.dart' as vm;
2: Make a projection Matrix.
vm.Matrix4 perspectiveMatrix = vm.makePerspectiveMatrix(vm.radians(150), 16/9,3, 20);
3: Make a Vector3 to move your plot, a 3x3 rotation Matrix to rotate your plot and another Vector3 to scale your plot.
vm.Vector3 location = vm.Vector3.array([100,-200,300]);
vm.Matrix3 rotation = vm.Matrix3.identity();
rotation.setRotationX(vm.radians(xRot));
rotation.setRotationY(vm.radians(yRot));
rotation.setRotationZ(vm.radians(zRot));
vm.Vector3 scale = vm.Vector3.array([1,1,1]);
4: With these, make a projection matrix from your local coordinate system to the world coordinate system
vm.Matrix4 localToWorldMatrix = Matrix4.compose(location, vm.Quaternion.fromRotation(rotation), scale);
5: Your final projection Matrix will be:
vm.Matrix4 finalMatrix = perspectiveMatrix*localToWorldMatrix;
6: If you change rotation recalculate matrix before every paint/update
7: Make a CustomPainter
8: Save your list of points as vm.Vector3's
List<vm.Vector3> points = [...]
9: Inside your update function: Copy all your points with vector.clone(), apply the projection and put them into another list
List<vm.Vector3> cloneList = [];
points.forEach((element) {
vm.Vector3 clone = element.clone();
clone.applyProjection(finalMatrix);
cloneList.add(clone);
});
10: Inside your draw function draw the points:
cloneList.forEach((element) {
canvas.drawCircle(Offset(element.storage[0]*size.width,element.storage[1]
*size.height), 1, Paint()..color = Colors.red);
});
11: Make 4 points for your coordinate system: (0,0,0),(10,0,0),(0,10,0),(0,0,10).
12: Apply projection to the 4 points for your coordinate system, draw lines, and your good to go

Find a nearly circular band of bright pixels in this image

This is the problem I have: I have an image as shown below. I want to detect the circular region which I have marked with a red line for display here (that particular bright ring).
Initially, this is what I do for now: (MATLAB)
binaryImage = imdilate(binaryImage,strel('disk',5));
binaryImage = imfill(binaryImage, 'holes'); % Fill holes.
binaryImage = bwareaopen(binaryImage, 20000); % Remove small blobs.
binaryImage = imerode(binaryImage,strel('disk',300));
out = binaryImage;
img_display = immultiply(binaryImage,rgb2gray(J1));
figure, imshow(img_display);
The output seems to be cut on one of the parts of the object (for a different image as input, not the one displayed above). I want an output in such a way that it is symmetric (its not always a perfect circle, when it is rotated).
I want to strictly avoid im2bw since as soon as I binarize, I lose a lot of information about the shape.
This is what I was thinking of:
I can detect the outer most circular (almost circular) contour of the image (shown in yellow). From this, I can find out the centroid and maybe find a circle which has a radius of 50% (to locate the region shown in red). But this won't be exactly symmetric since the object is slightly tilted. How can I tackle this issue?
I have attached another image where object is slightly tilted here
I'd try messing around with the 'log' filter. The region you want is essentially low values of the 2nd order derivative (i.e. where the slope is decreasing), and you can detect these regions by using a log filter and finding negative values. Here's a very basic outline of what you can do, and then tweak it to your needs.
img = im2double(rgb2gray(imread('wheel.png')));
img = imresize(img, 0.25, 'bicubic');
filt_img = imfilter(img, fspecial('log',31,5));
bin_img = filt_img < 0;
subplot(2,2,1);
imshow(filt_img,[]);
% Get regionprops
rp = regionprops(bin_img,'EulerNumber','Eccentricity','Area','PixelIdxList','PixelList');
rp = rp([rp.EulerNumber] == 0 & [rp.Eccentricity] < 0.5 & [rp.Area] > 2000);
bin_img(:) = false;
bin_img(vertcat(rp.PixelIdxList)) = true;
subplot(2,2,2);
imshow(bin_img,[]);
bin_img(:) = false;
bin_img(rp(1).PixelIdxList) = true;
bin_img = imfill(bin_img,'holes');
img_new = img;
img_new(~bin_img) = 0;
subplot(2,2,3);
imshow(img_new,[]);
bin_img(:) = false;
bin_img(rp(2).PixelIdxList) = true;
bin_img = imfill(bin_img,'holes');
img_new = img;
img_new(~bin_img) = 0;
subplot(2,2,4);
imshow(img_new,[]);
Output:

How to draw the lines or edges of a cone in matlab

I am trying to draw the lines or the edges of a cone using plot3 in matlab. Any help please? I do not need the surface. I need the edges only. SO that I can patch something on it. A useful link. But i need the circle at the bottom:
https://patentimages.storage.googleapis.com/US8514658B2/US08514658-20130820-D00021.png
Few horizontal lines are fine. But no tilted line as i need to patch something inside.
cylinder is your friend here...
You just need to pass it a vector of radii* and transpose the output*...
* negative radii tending to zero will flip the order so the apex is on top...
* so it draws rings not lines from the base to the apex
numRings = 10;
numPointsAround = 100;
[x,y,z] = cylinder(linspace(-1,0,nlines),numPointsAround);
plot3(y.',x.',z.','-k')
I think this is what you want. Most of the answer is directly taken from the above answer by #RTL.
numRings = 2;
numPointsAround = 100;
[x,y,z] = cylinder(linspace(-1,0,numRings),numPointsAround);
plot3(y.',x.',z.','-k')
hold on;line([-0.5878;0], [0.809;0],[0;1]);
hold on;line([0.9511;0], [-0.309;0],[0;1]);
axis square

How to add ILContourPlot to custom Z-axis location in ILPlotCube

I have three 2D-arrays that all have same X and Y coordinates but different values.
Each of these arrays represent a temperature of a room in certain height (eg. array1 = 10m, array2 = 5m, array3= 3m).
I have created a ILPlotCube that has three different ILContourPlots for these arrays but all of them get positioned to same Z-axis spot of cube (0):
this.scene = new ILScene();
ILPlotCube pc = new ILPlotCube(twoDMode: false);
ILArray<float> TA = tempRoom.GetILArray("TA");
ILContourPlot cpa = new ILContourPlot(TA, create3D: false);
ILArray<float> TB = tempRoom.GetILArray("TB");
ILContourPlot cpb = new ILContourPlot(TB, create3D: false);
ILArray<float> TC = tempRoom.GetILArray("TC");
ILContourPlot cpc = new ILContourPlot(TC, create3D: false);
pc.Add(cpa);
pc.Add(cpb);
pc.Add(cpc);
scene.Add(pc);
ilPanel1.Scene = this.scene;
ilPanel1.Refresh();
Image of result: http://i.stack.imgur.com/VNLgB.jpg
How can I set manually range of the Z-axis of cube shown in picture and manually set Z-axis-position of each ILContourPlot without messing up contours in ILContourPlots?
Contour plots in ILNumerics are regular scene graph objects - just like evey other plot. You can transform them in arbitray ways using regular group objects:
ILArray<float> A = ILMath.tosingle(ILSpecialData.terrain);
ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
new ILGroup(translate: new Vector3(0,0,10)) {
new ILContourPlot(A["0:50;0:50"])
},
new ILGroup(translate: new Vector3(0,0,5)) {
new ILContourPlot(A["50:100;50:100"],lineWidth: 3)
},
new ILGroup(translate: new Vector3(0,0,3)) {
new ILContourPlot(A["150:200;150:200"])
}
});
Gives:
But if you use it in a 2D setup it gets confusing quickly. Obviously you have to use the configuration options for lines and contour levels in order to distinguish individual contour plots. Or use a 3D view.

ILShapes not drawn when added as a children to ILScreenObject

I am generating image plot by setting the surface plot in 2d mode. I am trying to draw the overlay crosshair as an ILScreenObject and move it to jog/navigate
through the surface points along the wireframe.
But any shapes I add to the ILScreenObject are not visible other than the ILLabel?
I am using the following code.
ILArray<float> specialData = ILSpecialData.sincf(20, 30);
ILSurface surface = new ILSurface(specialData);
surface.MouseClick += surface_MouseClick;
ILPlotCube cube = new ILPlotCube();
cube.Add(surface);
//construct ILScreenobject
ILScreenObject screenObj = new ILScreenObject();
screenObj.Children.Add(new ILLabel("test label"));
screenObj.Children.Add(Shapes.RectangleFilled);
ilPanel1.Scene.Add(cube);
ilPanel1.Scene.Camera.Add(screenObj);
ilPanel1.Refresh();
All I could see with this code is a label centered on the image plot. Could anyone suggest me any possible solution for this? Thanks.