THREE.js - Texture mapping requirements - three.js

Intro
I have a web service that returns a json result that contains an image path.
These images are not necessarily square images (e.g. 200px x 250px).
Problem
It seems non-square images are not supported for texture mapping. In order for the texture mapping to work I have to manually download the image, resize it, and use that image for the texture mapping (and it works).
Questions
A) Could there be a way to make three.js/webgl use non-square images for texture mapping?
B) Could there be a way to programmatically load & resize an image and subsequently load it for texture mapping?
Thanks all.
Possible Solution?
I found what could be a viable option. Let me know what you guys think of this.
Basically, I will load the remote image and draw to a Canvas element which is square in size. Then I can get the image from the canvas (.getImageData) and save it to my web server's image folder (if this cant be done then I can just keep the image on the canvas). Finally, load the image for texture mapping.
I know this is pretty vague and simplistic. But hey, simpler the better, right?
Will this work?

DON'T resize it in a non-conformal manner, just take a square section (e.g., if the image is 250 X 220, just chop out a 220 X 220 sub-image). The texture classification algorithm may very well depend upon angles and related features that your skew-by-resize may short-circuit.

Related

Using a TreeMap with images

For representing most popular artists from EchoNest API, I've been trying to set-up Silverlight Toolkit's TreeMap using images, their TreeItemDefinition.ValueBinding being defined as the area of the image.
While it mostly fills up the space when the image stretch is set to 'Fill' :
When setting image stretch to 'Uniform' a lot of blank spaces remain :
On this post, image carving is suggested : Treemapping with a given aspect ratio
How can I know which images should be carved and at what dimensions they should be carved if possible at all ?
Is this problem solvable without human intervention for a good result ?
I don't think there is a way to know which images should be carved and at what dimensions they should be carved. An ok-ish euristic might be to check if the mean energy of an image is > a certain threshold (this can be refined to check only blocks of every image, and combining the result later: if the image has blocks without details/energy, it can be carved, at least in that section).
What i think would be better is to apply seam carving to the already composed image: that will try to carve out the white outlines (adding "artificial" energy to the patches of images might lead to even better results, preserving more the shapes of each image). This paper might be of use to check out other image resizing methods too.

Issue with NPOT Atlas (C++/iOS) using glTexCoordPointer

My app uses an atlas and reaches parts of it to display items using glTexCoordPointer.
It works well with power-of-two textures, but I wanted to use NPOT to reduce the amount of memory used.
Actually, the picture itself is well loaded with the linear filter and clamp-to-edge wrapping (the content displayed comes from the pic, even with alpha), but the display is deformed.
The coordinates are not the correct ones, and the "shape" is more a trapezoid than a rectangle.
I guessed I had to play with glEnable(), passing GL_TEXTURE_2D in the case of a POT texture, and GL_APPLE_texture_2D_limited_npot in the other case, but I cannot find a way to do so.
Also, I do not have the GL_TEXTURE_RECTANGLE_ARB, I don't know if it is an issue...
Anyone had the same kind of problem ?
Since OpenGL-2 (i.e. for about 10 years) there are no longer constraints on the size of a regular texture. You can use whatever image size you want, it will just work.

What is the fastest way to rotate a jpg image file?

I am working on some batch routines to manage large libraries of jpg files. I have a nice routine that will quickly downsize 4mb+ files down to 40kb+. Using CCR.Exif, I can determine if an image needs to be rotated. My problem is that I can't find any code to rotate the image before I save it. I really need to be able to do this without incurring the overhead of bringing the image to screen.
I'm using the built-in jpeg.pas; I found another library by Gabriel Corneanu at CodeCentral, but it hasn't been updated for DXE2. All I need to do is a 90° rotation.
Any help will be greatly appreciated!
JPGs are compressed and must be rendered before you can work with the image data. Even if it is a non-visible canvas, they still need to be loaded into a component that renders them. Then you can use Windows API calls to rotate the image by directly accessing the canvas. I haven't rotated the image before, but I have manipulated it in other ways by accessing the canvas.
GR32 and EFG are both good sites with several components and algorithms. Here is one example on EFG's site that rotates an image. The code is Delphi 3, but it should still work fine for image manipulation.
EFG Example with Source
TImage32 has a method to rotate the image 90 degrees as well. See TImage32.Bitmap.Rotate90. TImage32 is part of the GR32 library and has been updated for Delphi-XE2.
svn co https://graphics32.svn.sourceforge.net/svnroot/graphics32/trunk graphics32
Also see: GR32 Homepage
If you need to rotate JPEG in steps by 90 degree, then look for lossless transformations.
For example irfanview.com has a special plugin DLL for it, though it does not have public API, but maybe you can ask Irfan Author for it or reverse-engineer it with debugger and cff explorer.
a lot of discussion might by just googled, including discussion how it is implemented.
https://www.google.ru/search?client=opera&q=lossless+jpeg+rotation
Component catalogues have that like
http://www.torry.net/quicksearchd.php?String=jpeg+lossless&Title=No
That will not work with rotation finer than 90 degree steps, but for orthogonal turns keep searchign for lossless jpeg transformations.
The fastest way to rotate a JPEG image would be to write a new / alternate pixel pump for the JPEG decoder that reads and decodes the JPEG pixels left to right (x,y), and writes them to bitmap memory as (y,x) - that is, writing one pixel per scanline at the same offset, instead of the normal mode of writing one pixel per column on the same scanline.
Anything else will be making multiple passes over the bitmap data.

How can I deblur an image in matlab?

I need to remove the blur this image:
Image source: http://www.flickr.com/photos/63036721#N02/5733034767/
Any Ideas?
Although previous answers are right when they say that you can't recover lost information, you could investigate a little and make a few guesses.
I downloaded your image in what seems to be the original size (75x75) and you can see here a zoomed segment (one little square = one pixel)
It seems a pretty linear grayscale! Let's verify it by plotting the intensities of the central row. In Mathematica:
ListLinePlot[First /# ImageData[i][[38]][[1 ;; 15]]]
So, it is effectively linear, starting at zero and ending at one.
So you may guess it was originally a B&W image, linearly blurred.
The easiest way to deblur that (not always giving good results, but enough in your case) is to binarize the image with a 0.5 threshold. Like this:
And this is a possible way. Just remember we are guessing a lot here!
HTH!
You cannot generally retrieve missing information.
If you know what it is an image of, in this case a Gaussian or Airy profile then it's probably an out of focus image of a point source - you can determine the characteristics of the point.
Another technique is to try and determine the character tics of the blurring - especially if you have many images form the same blurred system. Then iteratively create a possible source image, blur it by that convolution and compare it to the blurred image.
This is the general technique used to make radio astronomy source maps (images) and was used for the flawed Hubble Space Telescope images
When working with images one of the most common things is to use a convolution filter. There is a "sharpen" filter that does what it can to remove blur from an image. An example of a sharpen filter can be found here:
http://www.panoramafactory.com/sharpness/sharpness.html
Some programs like matlab make convolution really easy: conv2(A,B)
And most nice photo editing have the filters under some name or another (sharpen usually).
But keep in mind that filters can only do so much. In theory, the actual information has been lost by the blurring process and it is impossible to perfectly reconstruct the initial image (no matter what TV will lead you to believe).
In this case it seems like you have a very simple image with only black and white. Knowing this about your image you could always use a simple threshold. Set everything above a certain threshold to white, and everything below to black. Once again most photo editing software makes this really easy.
You cannot retrieve missing information, but under certain assumptions you can sharpen.
Try unsharp masking.

Display Image over map layer in GeoServer

I am newbie when it comes to GeoServer and trying to figure out if there is an easy way to display images on top of map layer.
A background: In my application, based on a search criteria, some polygons are drawn on the map. Each polygon has a corresponding image (in TIFF format) that is stored somewhere. I want to load the image on top of the map when the user zooms in to a certain zoom level.
I know this can be done using openLayers but since my images are in TIFF format, (openLayers is not able to render TIFF images as far as i know) i have to convert them to .PNG first which would be very slow considering the number of images i have.
Hence I was wondering whether it would be possible to create a image layer that would retrieve an image of a certain polygon at a certain zoom level. If so, could anyone point me to an example or give me an idea on whether this is possible.
I am using spring 2.5, tomcat 5, java 1.6 and geoserver 2.0
Thanks.
GeoServer's styling language, SLD, supports using an image file to provide the fill texture when rendering polygons. If the number of polygons that you want to handle is small, you could just set up a style rule for each polygon with its own image URL for the fill. Otherwise, I'd recommend establishing a formulaic mapping from data attributes to image URLs, and using GeoServer's dynamic symbolizer feature to reference the images.

Resources