3D reconstruction, matlab - image-processing

I have image A and image B from same camera.
Points in Image A
PA=[
1 2172 998.9
2 2405 225.2
3 1480 1420
4 1045 1342
5 3039 1789
6 3727 968.7
7 1038 443.1
8 3606 856.6
9 1248 520.1
10 2189 976.8
]
Points in Image B
PB=[
1 2363 1598
2 2551 840.7
3 1768 2045
4 1404 1985
5 3040 2335
6 3636 1485
7 1393 1142
8 3514 1379
9 1550 1199
10 2378 1575]
t=1e-4;
Fundamental matrix
[F, inliers] = ransacfitfundmatrix(x1, x2, t);
F=[ 5.12243654806919e-009 -5.65511649689218e-008 -3.90901140383986e-006
9.48853562184938e-008 4.56036186476569e-008 -0.00133231474573608
-0.000178137312702315 0.00112651242300972 1.10421882784367]
Camera file
focallength =18.6188 mm
format size
width =22.6791 mm
height=15.1130 mm
Image size
5184*3456 pixel
Principle point
x0=11.5399 mm
y0=07.8574 mm
lens distortion (ideal)
K1=0 mm
K2=0 mm
K3=0
P1=0mm
P2=0 mm
Homography
H = vgg_H_from_x_lin(x1,x2)
**Question A= I want to get back PointsB
e.g.,
PointsB(:,1)==H*x1(:,1)
The results are wrong, why, any thing missing
More detail:
x2(:,1)'*F*x1(:,1)= -0.000644154818346676 % I guess its OK.
PointsB(:,1)==H*x1(:,1)= [ 2240.66095080911
1522.92361373263
0.953866074561989] %%%%%% WHY not 1
PB=[ 1 2363 1598]; SHOULD BE
Question B= How can I have 3D points from above informations.
Any link or matlab code would be helpful.
How can I use
vgg_X_from_xP_lin.m 3D point from image projections and cameras,
linear
X = vgg_X_from_xP_lin(u,P,imsize) % what is u

Are the two images taken with the same camera?
Question A: what you are looking for is point correspondences between the two images. One way to find corresponding points is to use local feature matching. There are many algorithms for detecting interest points and finding feature desriptors, such as SIFT, SURF, BRISK, FREAK, etc.
Question B: You can get the 3D points using triangulation. Also see Direct Linear Transformation in Multiple View Geometry in computer vision by Hartley and Zisserman.

Related

missing data in time series

As im so new to this field and im trying to explore the data for a time series, and find the missing values and count them and study a distribution of their length and fill in these gaps, the thing is i have, let's say 10 file.txt and for each file i have 2 columns as follows:
C1 C2
944 0
920 1
920 2
928 3
912 7
920 8
920 9
880 10
888 11
920 12
944 13
and so on... lets say till 100 and not necessarily the 10 files have the same number of observations.
so here for example the missing values and not necessarily appears in all files that i have, missing value are: 4,5 and 6 in C2 and the corresponding 1st column C1(measured in milliseconds, so the value of 928ms is not a time neighbor of 912ms). So i want to find those gaps(the total missing values in all 10 files) and show a histogram of their lengths.
i wrote a piece of code in R, but the problem is that i don't get the exact total number that i should have for the missing values.
path = "files path"
out.file<-data.frame(TS = 0, Index = 0, File = '')
file.names <- dir(path, pattern =".txt")
for(i in 1:length(file.names)){
file <- cbind(read.table(file.names[i],
header=F,
sep ="\t",
stringsAsFactors=FALSE),
file.names[i])
colnames(file) <- c('TS', 'Index', 'File')
out.file <- rbind(out.file, file)
}
d = dim(out.file)[1]
misDa = 0
for(i in 2:(d-1)){
if(abs(out.file$Index[i]-out.file$Index[i+1]) > 1)
misDa = misDa+1
}
Hard to give specific hints without having a more extensive example of your data that contains some of the actual NAs.
If you are using R (like it seems) the naniar and the imputeTS packages offer nice functions for missing data visualizations.
Some examples from the naniar package, which is especially good for multivariate data (more plot examples):
Some examples from the imputeTS package, which is especially good for time series data (additional plot examples):

GLMM glmer and glmmADMB - comparison error

I am trying to compare if there are differences in the number of obtained seeds in five different populations with different applied treatments, and having maternal plant and paternal plant as random effects. First I tried to fit a glmer model.
dat <-dat [,c(12,7,6,13,8,11)]
dat$parents<-factor(paste(dat$mother,dat$father,sep="_"))
compareTreat <- function(d)
{
d$treatment <-factor(d$treatment)
print (tapply(d$pop,list(d$pop,d$treatment),length))
print(summary(fit<-glmer(seed_no~treatment+(1|pop/mother)+
(1|pop/father),data=d,family="poisson")))
}
Then, I compared two treatments in two populations (pop 64 and pop 121, in that case). The other populations do not have this particular treatments, so I get NA values for those.
compareTreat(subset(dat,treatment%in%c("IE 5x","IE 7x")&pop%in%c(64,121)))
This is the output:
IE 5x IE 7x
10 NA NA
45 NA NA
64 31 27
121 33 28
144 NA NA
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: poisson ( log )
Formula: seed_no ~ treatment + (1 | pop/mother) + (1 | pop/father)
Data: d
AIC BIC logLik deviance df.resid
592.5 609.2 -290.2 580.5 113
Scaled residuals:
Min 1Q Median 3Q Max
-1.8950 -0.8038 -0.2178 0.4440 1.7991
Random effects:
Groups Name Variance Std.Dev.
father.pop (Intercept) 3.566e-01 5.971e-01
mother.pop (Intercept) 9.456e-01 9.724e-01
pop (Intercept) 1.083e-10 1.041e-05
pop.1 (Intercept) 1.017e-10 1.008e-05
Number of obs: 119, groups: father:pop, 81; mother:pop, 24; pop, 2
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.74664 0.24916 2.997 0.00273 **
treatmentIE 7x -0.05789 0.17894 -0.324 0.74629
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr)
tretmntIE7x -0.364
It seems there are no differences between treatments. But as there are many zeros in the data, a zero-inflated model would be worthy to try. I tried with glmmabmd, and I wrote the script like this:
compareTreat<-function(d)
{
d$treatment<-factor(d$treatment)
print(tapply(d$pop,list(d$pop,d$treatment), length))
print(summary(fit_zip<-glmmadmb(seed_no~treatment + (1|pop/mother)+
(1|pop/father),data=d,family="poisson", zeroInflation=TRUE)))
}
Then I compared again the treatments. Here I have not changed the code.
compareTreat(subset(dat,treatment%in%c("IE 5x","IE 7x")&pop%in%c(64,121)))
But in that case, the output is
IE 5x IE 7x
10 NA NA
45 NA NA
64 31 27
121 33 28
144 NA NA
Error in pop:father : NA/NaN argument
In addition: Warning messages:
1: In pop:father :
numerical expression has 119 elements: only the first used
2: In pop:father :
numerical expression has 119 elements: only the first used
3: In eval(parse(text = x), data) : NAs introduced by coercion
Called from: eval(parse(text = x), data)
I tried to change everything I came up with, but I still don't know where the problem is.
If I remove the (1|pop/father) from the glmmadmb script, the model runs, but it feels not correct. I wonder if the mistake is in the loop prior to the glmmadmb but it worked OK in the glmer model, or if it is in the comparison itself after the model. I tried as well to remove NAs with na.omit in case that was an issue, but it did not make a difference. Why does the script stop and does not continue running?
I am a student beginner with RStudio, my version is 3.4.2, called Short Summer. If someone with experience could point me in the right direction I would be very grateful!
H.

Artificial Neural Network Toplogy

I am currently trying to revise for my final year exams and came across this question, I have looked everywhere in my lecture slides for any sort of help and cannot find any. Any help in providing insight in to how to solve this question would be appreciated (I am not just asking for the answer, I need to comprehend the topic). Furthermore, do I assume that all inputs are equal to 1? Do i include 7 inputs in the input layer? Im at a loss as to how to answer.
The question is as follows:
b) Determine, with justification, the simplest type and topology (i.e. number of neurons & layers) of artificial neural network that could learn the data set below.
Click here for picture of the dataset.
If I'm not mistaken, you have two inputs X1, X2, and one target output. For each input consisting, of two numbers X1, X2, the appropriate output ("target") is given.
As a first step, you could sketch the seven data points - just draw the 3 ones and 4 zeroes at the right places on on the square (X1, X2) ∈ [0, 1.05] × [0, 1]. Maybe you remember something similar from the lecture, possibly near a mention of "XOR".
The edit queue is full, so adding data from the linked image here
Pattern X1 X2 Target
1 0.01 -0.1 1
2 0.90 0.09 0
3 0.89 -0.05 0
4 1.05 0.95 1
5 -0.01 0.12 0
6 1.05 0.97 1
7 0.98 0.10 0
It looks like 1 possible solution is X1 >= 1.0 OR X2 <= -0.1
Alternatively, if you round each of X1 and X2, it becomes
Pattern X1 X2 Target
1 0 0 1
2 1 0 0
3 1 0 0
4 1 1 1
5 0 0 0
6 1 1 1
7 1 0 0
Then it IS XOR, and the solution is round(X1) XOR round(X2). In that case you can use 1 activation layer (like round, RELU, sigmoid, linear), 1 hidden layer of 2 neurons and 1 output layer of 1 neuron.
See this stackoverflow post for a detail of how to solve XOR with a neural net.

How correlation help in matching two images?

It is known that if we are finding the most matching window to the current window in the entire image, then wherever the correlation is maximised then that is the matching window.
[22 12 14] (window)
(image)
[22 12 34 54 ]
[112 34 54 111 ]
[12 22 12 34 ]
[11 22 12 14 ]
But correlation is product of corresponding values in two windows.
So, if some of the window have high intensity values then they will always provide better match. e.g. in above example we will have higher correlation value for 2nd row.
Probably you need Normalized Cross Correlation, the maximum will be in 4th row.

Exporting blender model to iOS and create physics body along the vertices

I am into my first 3D game. I am using blender to create my model, using bullet for physics, and Isgl3D game engine.
So far, I am able to
Create models in blender
Export it to iPhone using Isgl3D libraries and show them.
Create physics bodies along the vertices of this models (for simple
models like cube and sphere.)
Now I want to create some complex irregular models and create physics rigid bodies along the vertices of that model. From my research, I found btTriangleMesh and btBvhTriangleMeshShape which can be used to create complex physics rigid bodies.
I found this thread, where bullet physics bodies are created along the vertices of a model exported from blender using POD importer. But they use btConvexHullShape to create the rigid body, which may not work in my case because my requirement has irregular complex models.
So I was trying to create a btTriangleMesh along the vertices of my model, so that I can create a btBvhTriangleMeshShape to create my rigid body.
So for starters I exported a cube (default blender cube, placed at origin) to understand how the vertices are stored in the Isgl3dMeshNode structure. This is my code
Isgl3dPODImporter * podImporter = [Isgl3dPODImporter
podImporterWithFile:#"simpleCube.pod"];
NSLog(#"number of meshes : %d", podImporter.numberOfMeshes);
[podImporter buildSceneObjects];
[podImporter addMeshesToScene:self.scene];
Isgl3dMeshNode * ground = [podImporter meshNodeWithName:#"Cube"];
btCollisionShape *groundShape = [self getCollisionShapeForNode:ground];
and my getCollisionShapeForNode method is
- (btCollisionShape*) getCollisionShapeForNode: (Isgl3dMeshNode*)node{
int numVertices = node.mesh.numberOfVertices;
NSLog(#"no of vertices : %d", numVertices);
NSLog(#"no of indices : %d", node.mesh.numberOfElements);
unsigned char * indices = node.mesh.indices;
btCollisionShape* collisionShape = nil;
btTriangleMesh* triangleMesh = new btTriangleMesh();
for (int i = 0; i < node.mesh.numberOfElements; i+=3) {
NSLog(#"%d %d %d", indices[i], indices[i+1], indices[i+2]);
}
}
And the NSLog statement prints..
number of meshes : 1
no of vertices : 24
no of indices : 36
and indices printed as
20 0 21
0 22 0
20 0 22
0 23 0
16 0 17
0 18 0
16 0 18
0 19 0
12 0 13
0 14 0
12 0 14
0 15 0
I am not sure I understand how the above given indices (and the vertices it points to) constitute 12 triangles (two in each phase) in the cube. I expect indices to be something like this (given below)
20 21 22 //phase 6
20 22 23
16 17 18 //phase 5
16 18 19
12 13 14 //phase 4
12 14 15
8 9 10 //phase 3
8 10 11
4 5 6 //phase 2
4 6 7
0 1 2 //phase 1
0 2 3
Probably I am missing something obvious. But I am stuck on this for sometime.
Anyone know how indices exported from .POD file differ from normal triangle indices. No way I could make a cube from the indices as it printed right now.
An additional question, Has anyone has an example code that creates triangle mesh to create physics rigid body.

Resources