| 149 | |
| 150 | template<typename T> |
| 151 | void ImageRemoveDistortion(const image::Image<T>& imageIn, |
| 152 | const camera::IntrinsicBase & intrinsicSource, |
| 153 | const camera::IntrinsicBase & intrinsicOutput, |
| 154 | image::Image<T>& image_ud, |
| 155 | T fillcolor, |
| 156 | const oiio::ROI& roi = oiio::ROI()) |
| 157 | { |
| 158 | int widthRoi = intrinsicOutput.w(); |
| 159 | int heightRoi = intrinsicOutput.h(); |
| 160 | int xOffset = 0; |
| 161 | int yOffset = 0; |
| 162 | if (roi.defined()) |
| 163 | { |
| 164 | widthRoi = roi.width(); |
| 165 | heightRoi = roi.height(); |
| 166 | xOffset = roi.xbegin; |
| 167 | yOffset = roi.ybegin; |
| 168 | } |
| 169 | |
| 170 | image_ud.resize(widthRoi, heightRoi, true, fillcolor); |
| 171 | const image::Sampler2d<image::SamplerLinear> sampler; |
| 172 | |
| 173 | #pragma omp parallel for |
| 174 | for (int y = 0; y < heightRoi; ++y) |
| 175 | { |
| 176 | for (int x = 0; x < widthRoi; ++x) |
| 177 | { |
| 178 | const Vec2 undisto_pix(x + xOffset, y + yOffset); |
| 179 | |
| 180 | // compute coordinates with distortion |
| 181 | const Vec2 disto_pix = intrinsicSource.cam2ima(intrinsicSource.addDistortion( |
| 182 | intrinsicOutput.ima2cam(undisto_pix))); |
| 183 | |
| 184 | // pick pixel if it is in the image domain |
| 185 | if (imageIn.contains(disto_pix(1), disto_pix(0))) |
| 186 | { |
| 187 | image_ud(y, x) = sampler(imageIn, disto_pix(1), disto_pix(0)); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @Brief process an image such that they appear captured by a new virtual intrinsic |