[37] | 1 | % * This code was used in the following articles:
|
---|
| 2 | % * [1] Learning 3-D Scene Structure from a Single Still Image,
|
---|
| 3 | % * Ashutosh Saxena, Min Sun, Andrew Y. Ng,
|
---|
| 4 | % * In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
|
---|
| 5 | % * (best paper)
|
---|
| 6 | % * [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
|
---|
| 7 | % * Ashutosh Saxena, Min Sun, Andrew Y. Ng,
|
---|
| 8 | % * In ICCV workshop on Virtual Representations and Modeling
|
---|
| 9 | % * of Large-scale environments (VRML), 2007.
|
---|
| 10 | % * [3] 3-D Depth Reconstruction from a Single Still Image,
|
---|
| 11 | % * Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
|
---|
| 12 | % * International Journal of Computer Vision (IJCV), Aug 2007.
|
---|
| 13 | % * [6] Learning Depth from Single Monocular Images,
|
---|
| 14 | % * Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
|
---|
| 15 | % * In Neural Information Processing Systems (NIPS) 18, 2005.
|
---|
| 16 | % *
|
---|
| 17 | % * These articles are available at:
|
---|
| 18 | % * http://make3d.stanford.edu/publications
|
---|
| 19 | % *
|
---|
| 20 | % * We request that you cite the papers [1], [3] and [6] in any of
|
---|
| 21 | % * your reports that uses this code.
|
---|
| 22 | % * Further, if you use the code in image3dstiching/ (multiple image version),
|
---|
| 23 | % * then please cite [2].
|
---|
| 24 | % *
|
---|
| 25 | % * If you use the code in third_party/, then PLEASE CITE and follow the
|
---|
| 26 | % * LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
|
---|
| 27 | % *
|
---|
| 28 | % * Finally, this code is for non-commercial use only. For further
|
---|
| 29 | % * information and to obtain a copy of the license, see
|
---|
| 30 | % *
|
---|
| 31 | % * http://make3d.stanford.edu/publications/code
|
---|
| 32 | % *
|
---|
| 33 | % * Also, the software distributed under the License is distributed on an
|
---|
| 34 | % * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
---|
| 35 | % * express or implied. See the License for the specific language governing
|
---|
| 36 | % * permissions and limitations under the License.
|
---|
| 37 | % *
|
---|
| 38 | % */
|
---|
| 39 | function [model1 model2] = RedundentPlanePick(defaultPara, ImgInfo1, ImgInfo2, Pair, GlobalScale, ... |
---|
| 40 | Img1IndexTarget, Img2IndexField, Img2IndexTarget, Img1IndexField) |
---|
| 41 | |
---|
| 42 | % [model1 model2] = RedundentPlanePick(defaultPara, ImgInfo1, ImgInfo2, ... |
---|
| 43 | % Img1IndexTarget, Img2IndexField, Img2IndexTarget, Img1IndexField) |
---|
| 44 | |
---|
| 45 | ErareTargetFlag = 1; |
---|
| 46 | CheckOwnRayFlag = 1; |
---|
| 47 | ErodeRemoveRegionFlag = 1; |
---|
| 48 | |
---|
| 49 | % Setup the Position3D in Global Scale |
---|
| 50 | Position3D1 = ImgInfo1.Model.PlaneParaInfo.Position3DFited = permute( ModelInfo1.Model.PlaneParaInfo.Position3DFited*GlobalScale(1),[ 3 1 2]); |
---|
| 51 | Position3D2 = ImgInfo2.Model.PlaneParaInfo.Position3DFited = permute( ModelInfo1.Model.PlaneParaInfo.Position3DFited*GlobalScale(2),[ 3 1 2]); |
---|
| 52 | |
---|
| 53 | % Pick out the Ray |
---|
| 54 | Ray1 = ImgInfo1.Model.PlaneParaInfo.Ray(:,:); |
---|
| 55 | Ray2 = ImgInfo2.Model.PlaneParaInfo.Ray(:,:); |
---|
| 56 | |
---|
| 57 | % Calculate the Target Surface Norm |
---|
| 58 | TargetFaceSetPoints1 = Position3D1(:,Img1IndexTarget(:)); |
---|
| 59 | TargerFaceSetPoints1 = reshape(TargerFaceSetPoints1, 3, 3, []); |
---|
| 60 | TargerFaceSetTwoEdge1 = TargerFaceSetPoints1(:,1:2,:) - repmat( TargerFaceSetPoints1(:,3,:),[ 1 2 1]); |
---|
| 61 | TargerSrufaceNormalVector1 = cross( TargerFaceSetTwoEdge1(:,1,:), TargerFaceSetTwoEdge1(:,2,:), 1); |
---|
| 62 | TargerSrufaceNormalVector1 = permute( TargerSrufaceNormalVector1./repmat( sqrt( sum( TargerSrufaceNormalVector1.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget |
---|
| 63 | |
---|
| 64 | TargetFaceSetPoints2 = Position3D2(:,Img2IndexTarget(:)); |
---|
| 65 | TargerFaceSetPoints2 = reshape(TargerFaceSetPoints2, 3, 3, []); |
---|
| 66 | TargerFaceSetTwoEdge2 = TargerFaceSetPoints2(:,1:2,:) - repmat( TargerFaceSetPoints2(:,3,:),[ 1 2 1]); |
---|
| 67 | TargerSrufaceNormalVector2 = cross( TargerFaceSetTwoEdge2(:,1,:), TargerFaceSetTwoEdge2(:,2,:), 1); |
---|
| 68 | TargerSrufaceNormalVector2 = permute( TargerSrufaceNormalVector2./repmat( sqrt( sum( TargerSrufaceNormalVector2.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget |
---|
| 69 | |
---|
| 70 | % Calculate the Field Surface Norm |
---|
| 71 | FieldFaceSetPoints1 = Position3D2(:,Img2IndexField(:)); |
---|
| 72 | FieldFaceSetPoints1 = reshape(FieldFaceSetPoints1, 3, 3, []); |
---|
| 73 | FieldFaceSetTwoEdge1 = FieldFaceSetPoints1(:,1:2,:) - repmat( FieldFaceSetPoints1(:,3,:),[ 1 2 1]); |
---|
| 74 | FieldSrufaceNormalVector1 = cross( FieldFaceSetTwoEdge1(:,1,:), FieldFaceSetTwoEdge1(:,2,:), 1); |
---|
| 75 | FieldSrufaceNormalVector1 = permute( FieldSrufaceNormalVector1./repmat( sqrt( sum( FieldSrufaceNormalVector1.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget |
---|
| 76 | |
---|
| 77 | FieldFaceSetPoints2 = Position3D1(:,Img1IndexField(:)); |
---|
| 78 | FieldFaceSetPoints2 = reshape(FieldFaceSetPoints2, 3, 3, []); |
---|
| 79 | FieldFaceSetTwoEdge2 = FieldFaceSetPoints2(:,1:2,:) - repmat( FieldFaceSetPoints2(:,3,:),[ 1 2 1]); |
---|
| 80 | FieldSrufaceNormalVector2 = cross( FieldFaceSetTwoEdge2(:,1,:), FieldFaceSetTwoEdge2(:,2,:), 1); |
---|
| 81 | FieldSrufaceNormalVector2 = permute( FieldSrufaceNormalVector2./repmat( sqrt( sum( FieldSrufaceNormalVector2.^2, 1)), [3 1 1]), [1 3 2]);% size 3 by NumberOfTarget |
---|
| 82 | |
---|
| 83 | % Calculate the portion that align with the ray |
---|
| 84 | SurfNorm1Target2Ray = abs( sum(TargerSrufaceNormalVector1.*Ray1(:,Img1IndexTarget), 1) ); |
---|
| 85 | if CheckOwnRayFlag |
---|
| 86 | SurfNorm1Field2Ray = abs( sum(FieldSrufaceNormalVector1.*Ray2(:,Img2IndexField), 1) ); |
---|
| 87 | else |
---|
| 88 | SurfNorm1Field2Ray = abs( sum( ( Pair.R*FieldSrufaceNormalVector1 + repmat(Pair.T, 1, size(FieldSrufaceNormalVector1, 2) )).*Ray1(:,Img1IndexTarget), 1) ); |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | % Calculate the portion that align with the ray |
---|
| 92 | SurfNorm2Target2Ray = sum( TargerSrufaceNormalVector2.*Ray2(:,Img2IndexTarget), 1) ; |
---|
| 93 | if CheckOwnRayFlag |
---|
| 94 | SurfNorm2Field2Ray = abs( sum( FieldSrufaceNormalVector2.*Ray1(:,Img1IndexField), 1) ); |
---|
| 95 | else |
---|
| 96 | SurfNorm2Field2Ray = abs( sum( (Pair.R'*FieldSrufaceNormalVector2 + repmat(-Pair.R'*Pair.T, 1, size(FieldSrufaceNormalVector2, 2) )).*Ray2(:,Img2IndexTarget), 1) ); |
---|
| 97 | end |
---|
| 98 | |
---|
| 99 | % =============================================================================== |
---|
| 100 | |
---|
| 101 | % Pick out the Plane has a bigger normalized PlanPrameter of the Ray |
---|
| 102 | if ErareTargetFlag |
---|
| 103 | Img1IndexTargetOutliers = abs(SurfNorm1Target2Ray) < abs(SurfNorm1Field2Ray); |
---|
| 104 | else |
---|
| 105 | Img1IndexTargetOutliers = Inf < abs(SurfNorm1Field2Ray); |
---|
| 106 | end |
---|
| 107 | Img2IndexFieldOutliers = ~Img1IndexTargetOutliers; |
---|
| 108 | |
---|
| 109 | if ErareTargetFlag |
---|
| 110 | Img2IndexTargetOutliers = abs(SurfNorm2Target2Ray) < abs(SurfNorm2Field2Ray); |
---|
| 111 | else |
---|
| 112 | Img2IndexTargetOutliers = Inf < abs(SurfNorm2Field2Ray); |
---|
| 113 | end |
---|
| 114 | Img1IndexFieldOutliers = ~Img2IndexTargetOutliers; |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | if ErodeRemoveRegionFlag |
---|
| 118 | OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri)); |
---|
| 119 | OriSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0; |
---|
| 120 | se = strel('ball',5,5); |
---|
| 121 | OriSup = imdilate(OriSup,se); |
---|
| 122 | Img1IndexTargetNew = find(OriSup == 0); |
---|
| 123 | |
---|
| 124 | OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri)); |
---|
| 125 | OriSup( Img2IndexField( Img2IndexFieldOutliers)) = 0; |
---|
| 126 | se = strel('ball',5,5); |
---|
| 127 | OriSup = imdilate(OriSup,se); |
---|
| 128 | Img2IndexFieldNew = find(OriSup == 0); |
---|
| 129 | |
---|
| 130 | OriSup = ones(size(ImgInfo2.Model.PlaneParaInfo.SupOri)); |
---|
| 131 | OriSup( Img2IndexTarget( Img2IndexTargetOutliers)) = 0; |
---|
| 132 | se = strel('ball',5,5); |
---|
| 133 | OriSup = imdilate(OriSup,se); |
---|
| 134 | Img2IndexTargetNew = find(OriSup == 0); |
---|
| 135 | |
---|
| 136 | OriSup = ones(size(ImgInfo1.Model.PlaneParaInfo.SupOri)); |
---|
| 137 | OriSup( Img1IndexField( Img1IndexFieldOutliers)) = 0; |
---|
| 138 | se = strel('ball',5,5); |
---|
| 139 | OriSup = imdilate(OriSup,se); |
---|
| 140 | Img1IndexFieldNew = find(OriSup == 0); |
---|
| 141 | end |
---|
| 142 | |
---|
| 143 | % Modify the Sup to 0 so that it won't rendered |
---|
| 144 | tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri; |
---|
| 145 | tempSup( Img1IndexTarget( Img1IndexTargetOutliers)) = 0; |
---|
| 146 | tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end); |
---|
| 147 | tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:); |
---|
| 148 | ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup; |
---|
| 149 | |
---|
| 150 | tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri; |
---|
| 151 | tempSup( Img2IndexField( Img2IndexFieldOutliers)) = 0; |
---|
| 152 | tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end); |
---|
| 153 | tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:); |
---|
| 154 | ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup; |
---|
| 155 | |
---|
| 156 | tempSup = ImgInfo2.Model.PlaneParaInfo.SupOri; |
---|
| 157 | tempSup( Img2IndexTarget( Img2IndexTargetOutliers)) = 0; |
---|
| 158 | tempSup(:,end) = ImgInfo2.Model.PlaneParaInfo.SupOri(:,end); |
---|
| 159 | tempSup(end,:) = ImgInfo2.Model.PlaneParaInfo.SupOri(end,:); |
---|
| 160 | ImgInfo2.Model.PlaneParaInfo.SupOri = tempSup; |
---|
| 161 | |
---|
| 162 | tempSup = ImgInfo1.Model.PlaneParaInfo.SupOri; |
---|
| 163 | tempSup( Img1IndexField( Img1IndexFieldOutliers)) = 0; |
---|
| 164 | tempSup(:,end) = ImgInfo1.Model.PlaneParaInfo.SupOri(:,end); |
---|
| 165 | tempSup(end,:) = ImgInfo1.Model.PlaneParaInfo.SupOri(end,:); |
---|
| 166 | ImgInfo1.Model.PlaneParaInfo.SupOri = tempSup; |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | % assign model1 and model2 |
---|
| 170 | model1 = ImgInfo1.Model; |
---|
| 171 | model2 = ImgInfo2.Model; |
---|
| 172 | |
---|
| 173 | return; |
---|
| 174 | |
---|