(whilst I have 2 questions, 1a and 1b, I think they are sufficiently interlinked to ask in a single SO question - in essence I would like a solution that can cater for both questions, thanks)
Bacground:
In MATLAB via texture mapping I'm attempting to effectively crop or repeat a .jpg file which is texture mapped to a CityGML (XML) LinearRing of a CityGML Polygon which forms a face of a CityGML 3D building model.
I'm struggling to understand how to deal with texture mapping where the texture coordinates are outside of the range [0, 1] and how to implement in MATLAB cropping and / or repeat of the source .jpg file using such texture coordinates.
Texture mapping here is non-parametric so interpolation to determine pixel positions can be linear. The face is a rectangle. The face is also on a plane so it is essentially a 2D problem. CityGML uses the COLLADA standard for texture mapping.
FYI I want to run various computer vision feature detection algorithms on the extended (repeated) or cropped .jpg image, though in practise I could run the algorithms on the original .jpg file and then repeat / remove the feature detection locations (in pixel space) based on the parameters for the extension or cropping.
Essentially I need to know those parameters.
Here is the source (not yet texture mapped) .jpg file ...
I'm clear on how the CityGML textureCoordinates ...
0 0 0.7 0 0.7 0.6 0 0.6 0 0 ... with CityGML wrapMode = "none" would effectively crop the corresponding .jpg by 40% of the height from the top down and by 30% of the width from the right-hand side. Using the syntax from MATLAB's imcrop documentation I can then in theory use I2 = imcrop(I,rect) on the .jpg image (I) once I've mapped the above textureCoordinates into pixels as the variable rect.
Question 1a:
However, I'm not clear how to programmatically determine the crop of image for the following textureCoordinates, where the values lie outside of the [0, 1] interval e.g. ...
9.996486000000003 0.6525461000000004 9.088325000000001 0.6525461000000004 9.088325000000001 -0.002156422999999508 9.996486000000003 -0.002156422999999508 9.996486000000003 0.6525461000000004 ... though I can see that by applying the above textureCoordinates (using 3DIS' CityViewer plug-in for Trimble's SketchUp) that the .jpg is cropped in from the top and from the left and repeated as a sliver at the bottom ...
... where using the textureCoordinates to calculate the vectors for each edge of the rectangle seems to give the crop percentages but how do I know if I'm processing these in the correct order to get the sign of the vector? (if that is the approach) I'm also aware that texture mapping can use modulo, which may bring the textureCoordinates into the [0, 1] range but am not clear how to do this.
Incidentally the corresponding CityGML Polygon LinearRing gml:PosList real-world coordinates in UTM Zone 30N (EPSG: 32630) are as follows ...
660044.175 5868582.941 13.239 660046.072 5868590.676 13.239 660046.072 5868590.676 0.0 660044.175 5868582.941 0.0 660044.175 5868582.941 13.239 Question 1b:
... and in addition I'm not clear how to deal with textureCoordinate values above 1 (also where wrapMode = "wrap") though I can see that this would mean that the texture is repeated, for example with textureCoordinates ...
1367.2299850672985 521.2362000000003 1367.2299850672985 718.2165000000003 282.26297058904646 718.2165000000003 282.26297058904646 521.2362000000003 1367.2299850672985 521.236200000000 ... and real-world coordinates ...
660081.831 5868584.426 13.239 660081.831 5868584.426 18.243 660055.048 5868590.915 18.243 660055.048 5868590.915 13.239 660081.831 5868584.426 13.239 ... for the source .jpg file (not yet texture mapped) ...
Summary:
So, this is a question partly about understanding texture mapping, and then, is there a way in MATLAB to use the textureCoordinates to programmatically crop and / or repeat the source .jpg?
(which would therefore, by implication, allow me to obtain the parameters for that cropping / repeating)
Thanks



No comments:
Post a Comment