ksam
YaBB Newbies
Offline
Posts: 19
Re: Displacement map filter code
Reply #4 - Jun 10th , 2008, 7:37pm
Hi PhiLho (and other programmers of course), As an inexperienced programmer, I spend some hours today surfing for code and pondering on the idea how we could make this caricature idea working. Your ideas about the non-displayed image and the semi-transparent circles are great, but I’m afraid I don’t know anyone to help me with OpenGL. I tried to think of a way to get the effect with simple code (and little math!) instead of OpenGL. You were probably right about this: we can combine a gray level map with a grid. About the project: do you know this ambiguous picture that seems to be a young woman if you look at it one way and an old woman if you look at it differently? For my project I will make ambiguous pictures, too, and do research about how people look at them. I think it’s a really funny project; I’m just struggling with this last part of the program! Anyway, the user sees a blurred image. When the user drags the mouse, the image is sharp in a small square at the location of the mouse. I totally agree that eye-tracking would be very interesting. It may be an option for future research or in an art installation. But for now it’s also nice as a low-tech solution. For example: artists could put their work on their websites and see how visitors looked at it. Or it can be a simple tool for online marketing research where marketers want to know how people look at visual advertisements. When the user releases the mouse, he/she sees an analysis of the path of the mouse. But after that comes the hard part: when ENTER is pressed, a caricature should appear. The parts where the user looked at (the mouse positions) should be enlarged while the image remains a nice picture as a whole. Your idea about the non-displayed gray level map sounds great. We could indeed draw a light semi-transparent circle at the current point, with its size inversely proportional to the current speed. The circle would be bright in the middle and gradually fade in the black background. This way we would have a gray level map. I have an idea about how to transform the image, but I’m not sure how it will work out. This idea is about a grid with x and y operations for each point done in a few for loops: 1) Create a fine grid of squares connected to the texture, beginning at 0,0 and ending at width, height (1280, 800 in my case). 2) Now we take each of the points of the grid except the first and last ones of the rows and columns (so the corners and edges of the image remain straight): for (i = 1, i = (last of the points of the grid in a row - 1), i ++) { for (j = 1, j = (last of the points of the grid in a column - 1), j ++) { 3) We calculate the difference in grayscale value v: Get the grayscale value at point i Get the grayscale value at point (i+1) v = grayscale value of point i - grayscale value of point (i + 1) 4) The whiter an area is, the more attention is had and the more it should be magnified. So the point should move from the white areas towards the dark areas, making the white areas bigger. If v = 0 then point i doesn’t move. If v > 0 then point i is whiter than point (i + 1), so the point moves towards point (i + 1) The x movement is positive: x-position point + (v * factor) If v < 0 then point i is darker than point (i + 1), so the point moves from point (i + 1) The x movement is negative (same formula with negative v): x-position point + (v * factor) The factor should make sure the point moves a nice amount of pixels (never more than one square of the grid!), depending on v (the difference in gray level). Maybe it should be rounded. 5) If this goes right, the points are moved in x-positions according to the gray levels of the map. Now we apply the same method for the y-positions, so steps 2 to 4 are repeated for y. Some boundaries: If x < 0, x = 0 If x > width (1280), x = width If y < 0, x = 0 If y > height (800), x = height Note 1: With this method the points never move too far at once depending on the size of the squares of the grid. But if the process is repeated a couple of times, the points will move further and the caricature will be extremer, because every time a point is moved, it may get a new grayscale value. Maybe it’s nice to make the displacement extremer every time you hit a certain key (nice toy). Note 2: The gray level map would not be a bump map, but a map for gray level difference. If we want a certain area to be greatly enlarged, the middle should be quite white, quickly becoming darker around it. Where there should be a smooth transition between enlarged image and normal size, we could make a slower transition between darker gray and black. Your idea of the light semi-transparent circle would do fine here, if we make the middle bright with first a quick transition towards darker and then a slower transition (a little like an S-curve with a small top; should this be programmed or would an image be more convenient as a ‘stamp’?). Do you think this is an option? It leaves out OpenGL and could give a nice effect (that is; if I’m right, which I can’t guarantee…). I can have this idea for code, but I know it’s quite something else to have it well implemented in Processing. Do you think you would be able to program this grayscale map and grid transformations?