Depth map merging or Point Cloud Merging - matlab

My goal is to create a single 3D point-cloud based on 2 pairs of images(AB, BC) and their projection matrices. Each image comes from the same camera (not video) with 3 distinct positions.
I use the "standard process": Point matching (sift or surf), keeping inliers only, finding the position, doing the bundle adjustment...images rectifications. Up to now everything works well.
Next I use the Matlab function "disparity" to create the 2 disparity maps, one for each pair of images.
Next i create 2 separated 3dpoint-clouds, one for each pair of images, using the projection matrices.
But, how can i merge the 2 points clouds coming from AB and BC. Apparently, the 3D coordinates depends on the "DisparityRange" parameters of the function disparity.
Did i miss a step in the process ?
Thanks in advance for any help
Alvaro

Please see the answer on MATLAB Answers

Problem solved.
The problem was that I processed wide-baseline stereo images as if they were short-baseline. Fatal Error!

Related

Avoiding for loop with cells and matrixes involved

I am trying to avoid the for loops and I have been reading through all the old posts there are about it but I am not able to solve my problem. I am new in MATLAB, so apologies for my ignorance.
The thing is that I have a 300x2 cell and in each one I have a 128x128x256 matrix. Each one is an image with 128x128 pixels and 256 channels per pixel. In the first column of the 300x2 cell I have my parallel intensity values and in the second one my perpendicular intensity values.
What I want to do is to take every pixel of every image (for each component) and sum the intensity values channel by channel.
The code I have is the following:
Image_par_channels=zeros(128,128,256);
Image_per_channels=zeros(128,128,256);
Image_tot_channels=zeros(128,128,256);
for a=1:128
for b=1:128
for j=1:256
for i=1:numfiles
Image_par_channels(a,b,j)=Image_par_channels(a,b,j)+Image_cell_par_per{i,1}(a,b,j);
Image_per_channels(a,b,j)=Image_per_channels(a,b,j)+Image_cell_par_per{i,2}(a,b,j);
end
Image_tot_channels(a,b,j)=Image_par_channels(a,b,j)+2*G*Image_per_channels(a,b,j);
end
end
end
I think I could speed it up introducing (:,:,j) instead of specifying a and b. But still a for loop. I am trying to use cellfun without any success due to my lack of expertise. Could you please give me a hand?
I would really appreciate it.
Many thanks and have a nice day!
Y
I believe you could do something like
Image_par_channels=zeros(128,128,256);
Image_per_channels=zeros(128,128,256);
Image_tot_channels=zeros(128,128,256);
for i=1:numfiles
Image_par_channels = Image_par_channels + Image_cell_par_per{i,1};
Image_per_channels = Image_per_channels + Image_cell_par_per{i,2};
end
Image_tot_channels = Image_par_channels + 2*G*Image_per_channels;
I haven't work with matlab in a long time, but I seem to recall you can do something like this. g is a constant.
EDIT:
Removed the +=. Incremental assignment is not an operator available in matlab. You should also note that Image_tot_channels can be build directly in the loop, if you don't need the other two variables later.

My observations are less than the feature vector of each. Any solution to overcome this?

I'm using GMM to fit my data to 256 Gaussians. I'm using Matlab's fitgmdist to achieve this.
gmm{i} = fitgmdist(model_feats, gaussians, 'Options',statset('MaxIter',1000), ...
'CovType','diagonal', 'SharedCov',false, 'Regularize',0.01, 'Start',cInd);
I am using RootSIFT to extract the features of each image. This produces a vector of 1x128 for each image.
Now I have 45 images maximum for each writer. So after feature extraction and everything the size of my model_feats is 45 x 128.
According to the help file for data arrangement for X is:
The rows of X correspond to observations, and columns correspond to
variables.
The problem I have is when I run the above function I am told that:
"X must have more rows than columns."
I have a total of 45 images for each writer. How will I be able to get this function to run? This is a strange limitation for such a function, I mean even if I am able to get 100 images for each writer it will not work.
I will appreciate any workaround to this.
P.S. I've tried the same with VL_Feat's vl_gmm and it works without any problems but I need this to work in Matlab not VL_FEAT.
With SIFT you usually don't compute the feature for the whole image, but literally hundreds of keypoints for each image. Then you won't have this problem anymore.
Next step then probably is a “bag of visual words” mapping of each image.

Find the connected component in matlab

Given a BW image that contains some connected components.
Then, given a single pixel P in the image. How to find which component that contains the pixel P? It is guaranteed that the pixel P is always on the white area in one of the connected components.
Currently, I use CC = bwconncomp(BW) than I iterate each component using 'for' loop. In the each component, I iterate the index pixel. For each pixels, I check whether the value equal to the (index of) pixel P or not. If I find it, I record the number of connected component.
However, it seems it is not efficient for this simple task. Any suggestion for improvement? Thank you very much in advance.
MATLAB provides multiple functions that implement connected-component in different ways.
In your example, I would suggest bwlabel.
http://www.mathworks.com/help/images/ref/bwlabel.html
[L, num] = bwlabel(imgBW) This will perform a full-image connected-component labeling on a black-and-white image.
After calling this function, the label value that pixel P belongs to can be read off the result matrix L, as in label_to_find = L(row, col) index. Simple as that.
To extract a mask image for that label, use logical(L == label_to_find).
If you use different software packages such as OpenCV you will be able to get better performance (efficiency in terms of cutting unnecessary or redundant computation), but in MATLAB the emphasis is on convenience and prototyping speed.

Suppress kinks in a plot matlab

I have a csv file which contains data like below:[1st row is header]
Element,State,Time
Water,Solid,1
Water,Solid,2
Water,Solid,3
Water,Solid,4
Water,Solid,5
Water,Solid,2
Water,Solid,3
Water,Solid,4
Water,Solid,5
Water,Solid,6
Water,Solid,7
Water,Solid,8
Water,Solid,7
Water,Solid,6
Water,Solid,5
Water,Solid,4
Water,Solid,3
The similar pattern is repeated for State: "Solid" replaced with Liquid and Gas.
And moreover the Element "Water" can be replaced by some other element too.
Time as Integer's are in seconds (to simplify) but can be any real number.
Additionally there might by some comment line starting with # in between the file.
Problem Statement: I want to eliminate the first dip in Time values and smooth out using some quadratic or cubic or polynomial interpolation [please notice the first change from 5->2 --->8. I want to replace these numbers to intermediate values giving a gradual/smooth increase from 5--->8].
And I wish this to be done for all the combinations of Elements and States.
Is this possible through some sort of coding in Matlab etc ?
Any Pointers will be helpful !!
Thanks in advance :)
You can use the interp1 function for 1D-interpolation. The syntax is
yi = interp1(x,y,xi,method)
where x are your original coordinates, y are your original values, xi are the coordinates at which you want the values to be interpolated at and yi are the interpolated values. method can be 'spline' (cubic spline interpolation), 'pchip' (piece-wise Hermite), 'cubic' (cubic polynomial) and others (see the documentation for details).
You have alot of options here, it really depends on the nature of your data, but I would start of with a simple moving average (MA) filter (which replaces each data point with the average of the neighboring data points), and see were that takes me. It's easy to implement, and fine-tuning the MA-span a couple of times on some sample data is usually enough.
http://www.mathworks.se/help/curvefit/smoothing-data.html
I would not try to fit a polynomial to the entire data set unless I really needed to compress it, (but to do so you can use the polyfit function).

Tanimoto Coefficient using Matlab

I need to calculate Tanimoto Coefficient. I don't know what's wrong in my code. I have 2 nearly similar images. But the value obtained using my code indicates that the two images are highly dissimilar. Kindly help me with my code.
%Tanimoto coeff
I=imread('sliver3.jpg');
J=imread('ref5.jpg');
figure,imshow(I),title('Original');
figure,imshow(J),title('Reference');
inter=intersect(I,J,'rows');
uni=union(I,J,'rows');
si=size(inter);
su=size(uni);
tc=si/su
I attach three images here. First one is the segmented output. Second is a reference image.Third is also a reference but which is highly dissimilar. So, the output must be that, first and second must be nearly similar and first and third must be highly dissimilar. But I'm getting the opposite.
For first two images, tc =0.4895
For first and third images, tc=0.5692
Kindly help me out.
I think you should use the sum() function on union and intersect instead of size() since the Tanimoto Coefficient is the "summation of the intersect"/"summation of the union"