Skip to main content.
June 30th, 2005

Quantization in HSV color-space

The past two nights I’ve been toying around with Matlab, making experiments with color spaces. Specifically, I worked on the idea of completely separating luminance from chrominance.
I did a few experiments, but the one that I want to report about is with HSV. HSV color model separates hue, saturation and value (or luminance/intensity). There are actually three similar but different models: HSV, HSL and HSI, but for my purpose, that doesn’t make much difference.
The experiment is about removing information on any of the three channels, to see which one is the most important, and how I can reduce the information while minimizing the visible artifacts.
I proceeded to created three different images, each leaving 2 channels intact, and one strongly quantized. For the intact channels, I kept the original 256 levels. While the quantized one was reduced to 8 levels.

Here is the original image:

Here a are the resulting images:

On the first row, there is the hue component, hue component with only 8 levels and then the image built using the quantized hue.
The second row expresses the same process, only this time quantizing the saturation.
On the third row the value (gray levels) is being quantized.

As expected, messing with the hue can be pretty messy. The color sensibly shifts and what’s green becomes brow !
The gray-level image is also visibly affected by quantization. It’s probably the worst of the three, but that doesn’t worry me, because it’s supposed to be compressed the JPEG way (quantization on DCT transformed data, in frequency domain).
Quantization on saturation is really not that much of a big deal, and that’s also what I was expecting.

So, now the real issue is with hue. The quantization clearly has some drastic effects. Using DCT would lead to some serious artifacts, as the ringing artifacts would bring, for example, cyan and yellow pixels around an original green one. Or perhaps I’m worrying too much. However, there would still need to be some special preprocessing, because hue values have a discontinuity on red. 255 and 0 are both very close to red. The lossy DCT would make a mess between 0 and 255 because it’s a drastic change.

Also it has to be noted that the quantization performed here was rather dumb, because I’m not selecting the most 8 used values, but I’m blindly rounding original values to 8 fixed ones (on a 256 scale that’s 256/8 = 32, selected values are 0, 32-1, 64-1, .., 256-1).
Using an actual palette of used values would ensure that no brown comes up where green should be. The green value would come into the palette as the most used one, instead of being snapped to a fixed value.

Next, I should probably try to properly quantize the hue, building a palette of used values. Possibly building separate palettes for separate areas of the image.

mumble

Posted by Davide Pasca as Image-processing at 1:43 AM EDT

3 Comments »

June 27th, 2005

Another Japanese summer begins

Summer has arrived and so did the humidity. Sweat smell is becoming more and more common. It’s pretty bad. I think, mostly due to the general humidity level, people’s sweat smells comes in a specific flavor. I’m rather dutiful with my igene, so I’m normally OK, however my wallet now started to smell ! I changed it last year because the old one was smelling. The old one was made of synthetic fabric, the new one is in leather, but still.. From now on I need to be more careful about the wallet too !

Another nasty problem with humidity is that the towels tend to get a bad odor very easily. I go wash my hands, I dry them with the towel, I go back to the desk.. and boom.. my hands stink !! Then I have to go get a fresh towel, wash my hands again (more than before) and dry them with the fresh towel (which is not quite as fresh anymore 8).
What a mission !!

Although air conditioners are just about everywhere, it’s hard to enjoy outside activities. Even at night the situation is pretty bad. One can’t just sit outside and enjoy the breeze. There isn’t any in Tokyo, and it would be hot an humid anyway !
From the news, I see that Italy isn’t faring too well. Two years ago I went for a summer vacation in August and I came back with a cold and several mosquito bites. The cold was due to the fact that the heat was so bad that I had to sleep with a window open and a fan directed on me (!). Another fan was by the window, one more on upstairs (same room, partially divided vertically) near my sister’s bed.
Last year the heat wasn’t so bad, this year seems to be bad again… and my parents still can’t decide on putting an air conditioner in the house.

Now that the weather talk is settled… this weekend I didn’t even try to be a nightlife lion (an Italian say goes: di notte leoni di giorno coglioni = lions by night, idiots by day). Friday, I went out, but came back relatively early. Saturday I came back even earlier and I did some coding !

On the coding side, I put my hands on a copy of Matlab. I need to find a solution with Scilab, as I can’t really afford Matlab. Especially, I doubt I’d be taken too seriously if I asked my employer to get a copy of Matlab (ah ah ah !!!).
All I really need from Scilab is the function to load and save images, even a mere BMP format. Maybe a few more functions would be nice. There is a free toolbox for image processing with Scilab, however, the Windows version is apparently outdated and it requires an old version of ImageMagick to work. That really set me off, as I didn’t want to uninstall the new ImageMagick and replace it with an old one !
However, upon careful read, it seems that the SIP toolbox needs to have the ImageMagick directory specified. This probably means that I can make the two versions of ImageMagick co-exist on my system.. not very clean, but I’ll have to try that.

mumble mumble

Posted by Davide Pasca as Uncategorized at 2:02 AM EDT

11 Comments »

June 22nd, 2005

Somewhat emotive but not instinctive (all spell-checked !)

It’s almost 2AM. Yesterday night I couldn’t sleep until around 5 ! It was dreadful, I had to call in sick, although only for the first half of the day. I went in at 1PM instead of 10AM.
Once I got in the office however, I was for most part, adrenalinic. I wrote quit a bit of code without dangling too much. Clearly productive, mostly due to the fact that I didn’t have to wake up at 9, shower, run, eat one large meal, etc.

M4D has finally gotten a decent shape. I added hooks to the model, material and texture classes. The hooks are a user-data pointer and a user-data-delete callback. Those hooks allow me to attach rendering related structures. A texture class will normally have just the name of the texture file, the attached user-data will provide a pointer to a structure/class used by the rendering subsystem.. which will contain whatever data is necessary to feed to OpenGL or Direct3D for actual rendering. Same goes for the model class, which, when is a mesh (a model that contains geometry) will have an hook to vertex and triangle data that can be fed directly to OpenGL (or, again, eventually, Direct3D).
I’m so far pretty happy with this, because it allows me to have a pretty solid and generic underlying engine which can be a starting point for actual hardware and API-dependent engines. Generality always comes to a price, but thinking optimized for a specific hardware and API from the start is comes to a bigger price. Generality was also the key-point for me, as the main goal was really to have a framework for 3D geometry storage and processing.

I should be in bed after this, but I need to add more 8)
A couple of days ago, on the movie channel on cable, I saw again Equilibrium (ohh, I see why they showed it again, it’s with the protagonist of Batman Begins 8). The movie is about a society where emotions are repressed with a "medicine" and fascist-style policing, as to avoid wars, which are touted as side-effect of people being influnced by emotions.
The topic is too big to be analyzed at 2:21AM.. but I think that the question is very big even at a personal level. In life I look back an see how the things that I could achieve were achieved thanks to focus and commitment, avoiding emotions, which normally would make one derail.
The movie shows that emotions are the essence of human life and shouldn’t be avoided. However, it’s also true that the human being’s main strength is the ability to override instincts for a greater goal. The movie (probably by design) doesn’t go deep enough to reveal that while emotions are generally good, they are also a lot more valuable than instincts. Instincts can bring some emotions, but not as refined as those that are brought by actions which are done while containing instincts ! (did I write that right ? ummm)
Basically, instinctively, people could fack around and crack each other’s skulls over some edible or some fuckable. Emotionally, it makes more sense to think twice before acting and use more logic.

The problem really, is that many let themselves go for instincts and forget about the more refined emotions. It’s something that everyone should think about. It’s something that can make a great difference in life.. the difference between being a sheep and a human.

And now it’s my time to go count the sheep !

zzzzzzzzzzzzzzzzzzzz

Posted by Davide Pasca as Uncategorized at 2:35 AM EDT

12 Comments »

June 21st, 2005

Gadgets, widgets, buttons, windows and libraries

Today I was… sleepy ! Yesterday night, I realized that I had no sleeping pills.. without them it’s always an issue.. especially for the day after !

zzzzzzzzz

Since last week, I did some research about writing GUI applications. More specifically, I wanted to give a try to those publicly available libraries such as wxWidgets and FLTK. Those libraries have great support. They are all more or less multi-platform, they come with lots of sample code and documentation.. So I figured, now that I’ve got a bit more acquainted with C++, that I’d give a try again and see if they looked any nicer from last time I checked them.
wxWidgets code doesn’t compile straight away under VS.NET. I had to make some manual changes to some library names, then it worked. It’s all based on sub-classing, something that I don’t particularly like. Also, events are handled using a lot of defines (so much for C++ design 8). The nice thing is that the GUI on Windows, really does look like Windows.. and not worse, like for FLTK.
FLTK as a much cleaner programming interface, a window is an object and it’s created when it’s needed, without inheritance. Unfortunately, even the edit boxes seem to be somewhat custom. So, the Japanese input is lost (some patch does support it). Also the file requester is completely custom, and definitely not as nice as the standard MS Windows one.

So, I’m back to my application framework. It’s not multi-platform, there is comparatively very little work behind, but it’s my code and it’s much simpler to use.

All this started because I thought of creating a few windows to hook to the video-capture library, to get the output in other color-spaces, to begin some testing. Instead I decided to procrastinate and do this little excursion into the world of GUI frameworks.
In the end I’m not too disappointed to find out that I don’t need to jump into a new adventure with some new huge, cross-platform library.

Posted by Davide Pasca as Uncategorized at 1:48 AM EDT

4 Comments »

June 20th, 2005

Lazy weekend

The weekend went by and productivity was rather low. Friday night I was in the mood to code, but an over-excited friend convinced me to, not only go out, but actually drink to an excess.. like it happens once or twice in a year. We really enjoyed ourselves at the time, but from the time I came back home, straight into Saturday, regret took over 8)
Saturday I mostly slept, then I partied.. but with water ! Went back home before 5 AM, watched a movie on TV, went to sleep at 7AM. Slept the rest of the day, till late afternoon, were I went to some cafe/pub with a friend. There was some sort of artsy American crowd. They had some events, strange music, pictures slide-show using a projector and a computer (I wont say which computer (..you can guess (…..Mac people !!!))).

And.. it seems I won’t be able to take my summer vacations ! No Italy for me this summer. I usually take two weeks (one standard + one of paid holidays). But this time around, there is some project starting and I’ll be in Tokyo busy hitting deadlines.
To fly over to Italy and back it’s a pain. However, I was really looking forward to meet my friends and relatives. I kept promising to my relatives that I’d try to go back more often and instead the situation is getting worse. Ummmmmm !!!!

On the coding side, I started pretty much to rewrite M4D (again !). I’m going to use new and delete and organize everything with a scene-graph. The final plan is to overload new and delete so that objects are allocated in specific pools. Basically, a scene should have a different pool of objects, one for each type. That is one pool of one type, for each scene. Not just one pool for one type. That means that new and deleted are overloaded not just per class, but using an extra parameter: an handle to a pool manager. This should generally improve memory management, and also give me the chance to safely handle the scene teardown: kill all the pools at once, no need for individual releases of objects.
I did read a bit about memory management in OOP. Some paper from Microsoft claims that it’s not necessarily a good thing to write a custom OO memory manager. Apparently the default memory manager is usually smart enough to avoid bad fragmentation and excessive CPU usage. Still, I like the idea of a more tight management. It may end up not making a big difference in performance, but I can see eventual benefits for debugging. However, in general, when a game is running, one shouldn’t fiddle too much with memory allocation and deallocations.

Time to zzzzz !

Posted by Davide Pasca as Uncategorized at 12:20 AM EDT

1 Comment »

June 16th, 2005

What I code is sometimes what others get

Yesterday evening we watched and episode of Nu, Pogodi!, courtesy of Mr.Rince ! The cartoon is in Russian, but with very little dialogue. It’s along the lines of The Road Runner (here comes Ragin’s comment.. !), but I like the idea that the wolf is a vandal. It makes it more amusing to see him fail. It’s a cartoon but actually reflects reality to some levels. From time to time I meet people that are vandals in a way or another, and while I care for everyone to live peacefully, I also am satisfied if I see those getting paid back for what they spread !
being racist towards vandalism is, I think, a positive thing. …cool.. I get to be prejudicial and good at the same time !

Today I spent good 12 hours in the office …my choice. I did quite a bit of research on scene graphs. That reminds me that a few years ago, a colleague told me he wanted to implement a scene graph, and I didn’t even know what he meant !
A scene graph is basically a tree. At every node there is an object, which could be something renderable (a bunch of polygons), or a camera, a light source, an abstract object that keeps informations to be distributed hierarchically, transformations, visibility, rendering material.
It works nicely on a logical point of view, but can get easily troublesome. To organize everything with a precise hierarchy isn’t so straightforward. Some scene graphs even expect one to render objects as they are parsed in the tree… I definitely have some doubt on that, as far as performance goes.
Although it’s too early to come to any solid conclusion, my current take on this is that it’s nice to have all into a scene graph, but one shouldn’t break his neck in trying to give a proper logical order to it. This is especially difficult when the scene is dynamic. You can’t really attach the tyres of a car to the road, that has to be governed by physics. The car is therefore yet another object that is linked to the root of the scene graph.
So, I decided that my scene graph is built around transformation nodes. Every object, be that a renderable mesh or a camera, will have the tree’s node structure as its header.

class model_c{    graph_node  _node    …};

class camera_c{    graph_node  _node    …};


The node has its usual child, previous and next pointers, plus the local transformation matrix and the accumulated global (world) transformation matrix.
Also, there is a field that describes the type of object where the node belongs to. This allows me to traverse the tree to update the transformation matrices but also implement a custom traversal that does some custom operation on a specific object type.
All this isn’t something that has a precise practical value. It is however one more generalization and therefore something that opens the door for unaccounted usage.

I like the idea of the generic traversal, to have all into a tree, even without following a strict logic (lots of objects hanging just by the root). It’s perhaps a small improvement into generalizing. Not necessarily useful to someone that designes and uses an engine, but I think that it can make a difference for an engine that needs to be used by others.
This is in fact my biggest worry: to write an engine that others won’t feel painful to use.

Posted by Davide Pasca as Uncategorized at 1:00 AM EDT

9 Comments »

June 14th, 2005

Tiredddddddddddd[d]

I feel tired all the way. Tired body, tired mind, tired to be tired !
Productivity might now be at the highest, but at least going in the office everyday forces me to do something 8)
Yesterday I’ve spent some time, among the other things, on the menu system. It already looked fairly nice, with those smooth shadows, but functionality was lacking. Namely, it didn’t support sub-menues ! Those are there now. Also I went back the behavior that I developed long time ago for RTMZ. Basically, right click brings up the main menu, or closes it or any currently active submenu. Once in a menu, it will follow the mouse, if the mouse is moving outside the menu. I’m not sure how logic it is, but I kind of got used to it.
On the real productive side, today I’ve more or less finished the automatic groups generator for objects. Here are two sample pictures. Red bounding boxes highlight the objects distribution. The first picture shows very few and large objects, the second one shows the effect of the automatic grouping.

This is going to give me a big improvement on performance. It allows me to do early culling of objects outside the view frustum, plus I could work out some geometry level of detail method.
I’ve also started to lay down a basic rendering engine. The usual big questions lay ahead. Right now I’m allocating one object at the time and I’m attaching the to the world with linked lists. I prefer arrays, but on a generic rendering engine, one should expect some pretty dynamic use.
Linked lists are only used to gather the objects into the world data-base. The actual transformation tree is a different issue. I don’t really have a well designed scene-graph system designed on code, or in mind for that matter. Objects are usually loaded with their own hierarchies. I support that in my file format, but there is always a number of things that one can or wants to do in an actual application/game. This is quite an issue for me, because I’ve much more experience writing 3D engines than actually using them !
I suppose that I should just go and aim at my goal as an application, whatever it is, and adapt the design around it. This is what I did with all the geometry and vertices mess. However, I feel the need to hurry up, because I want to settle these important things before I’m being asked to get busy on something that others may have to use… last thing I want to do is to experiment on other people.. especially considering that once code is being used by others, it’s much more difficult to impose sudden and radical changes.

woo !!


I realize that all this technical talk can bore to death some, but this is actually a big relief for me. It puts me back into my world (nerdy !). It’s all virtual but gives me a lot more freedom. Playing with 3D graphics is a way to dream one’s way into something. Everyday’s life is generally pretty boring. People that try to gather all pleasure directly or indirectly from physical world, find themselves limited by a lot of obstacles. To be bearable, life needs to be softened from time to time. Many form of entertainment are possible. Some are simpler than others, some are more productive than others. I could play games and watch movies all the time, but that makes me feel terribly unproductive.
It’s perhaps an unhealthy way of thinking, but I realize that it’s the need that pushes people. If I’m happy, if I don’t feel the need to be vindicated, then I won’t be very productive.
…now, all this would work much better if I did get those famous 8 hours of sleep every night. Gambarimasu !

Posted by Davide Pasca as Uncategorized at 10:27 PM EDT

5 Comments »

June 11th, 2005

I display-list you !

Yesterday at work I worked most of the day to make the changes to M4D. Then I continued at home on and off ’till the morning. Eventually I went to sleep at 7:20(AM). Time went by as I talked to my parents on the Internet, then watched a movie on TV (interesting Home Fries), then an episode of OZ.

As for the coding, things seem to work well again. I’ve written a separate module to transform the 3D database into one suitable for display-lists.
For each triangle there are 3 vertices, each vertex has up to four indices, referring to position, texture, color and normal pools of coordinates. Each combination of those four indices, represents an actual whole vertex that I have to generate for the display-list. To do the operation efficiently wasn’t so straightforward. I went on and utilized a system that I developed before. Combinations of indices utilized in triangles generate new vertices, but to avoid repetition, every time I need to generate a vertex I check if it’s already in the list. I keep the 4-indices list sorted as I build it. Insertion can be slow (because of all shifting of pieces of the array), but search is very fast, using a binary search method.

On the models’ side, my sister told me that she has a new model in the works. A room that she’s building for a project at the university. There should be some nice furnitures too. Her task for that project is is really about illumination distribution, not furniture design, however she found a site of a company that does furnitures and that gives out the 3D of their models for free, for those willing to register.
Apparently the quality of those models is good too. While she agrees that usually it’s a nightmare to try find 3D models freely available on the net.
Speaking of lighting, my sister told me that for that project she’s going to use 3DS Max 6 for rendering. Apparently, there is an option to provide some illumination parameters that match those provided by companies that make light sources (the real ones 8).

Interesting, but it’s already saturday afternoon and I should shower and go out ! Although I’m sleepy and I would like to keep with the coding.

zzzzzzzzzzzz

Posted by Davide Pasca as Uncategorized at 3:06 PM EDT

4 Comments »

June 10th, 2005

Dietrofront !

Dietrofront is an Italian word that I believe originates as a military command, to impart an order or describe a situation in which a 180 degrees turn is made.
This is what I did today with my engine/M4D/thingy. In the last big change, I removed the material ID from the triangle description, to leave only the three vertex indices. Triangles were then grouped into pools with the same material. This is suitable for real-time rendering. A structure that I can pass straight into OpenGL or Direct3D to be displayed.
Unfortunately this added quite a bit of complexity. I did bear with it, until today I decided to change how the vertices are organized. The change was going to affect the triangle structure, rendering it real-time unfriendly anyway. So, back is the material ID into the triangle structure, plus now vertex attributes are distributed independently on separate lists. Practically, this means that a triangle will have now 3 indices for the 3 vertices describing the position, plus 3 indices for the normals at the vertices, plus 3 indices for texture, and so on..
In so doing, I can keep the position vertices shared between triangles as they are meant, instead of having to duplicate them every time that there is a diverging attribute (you pretty much have to be a 3D programmer to get this, without much explanation).

The code is still not compiling, too many changes to make in one day. But I think that eventually this will make things easier for all those geometrical operations that I’m trying to do.

For real-time the options are two. The simplest one is to use the OpenGL immediate mode and record a display list. However, for best performance and for Direct3D, I will need to build a separate unit of code that generates all the vertex permutations necessary for them to be used by triangles and strips with just one index per vertex. I’ve done this before in an XSI converter. I could reuse some code, but I may as well rewrite it for efficiency.

Although I consider myself a fairily experienced 3D programmer, this teaching me quite a bit..

Posted by Davide Pasca as Uncategorized at 1:34 AM EDT

4 Comments »

June 9th, 2005

More on 3D partitioning

Today I changed the algorithm. The goal is to isolate clusters of triangles, mostly meshes, that are in the same database, but that are practically meant to be separate objects.
What I tried to do today was to take one triangle and follow its connections. For each vertex of the triangle I follow the triangles connected to those vertices recursively, until there are no more connections.
To do this, first I weld together all those vertices that are practically at the same position, but that perhaps are duplicated due to the necessity of having different texture coordinates or normals. Then I build an array where each element corresponds to a vertex, and carries a list of triangles that use that vertex. This array of triangles-per-vertex, speed up the vertex-triangle correlation and make it much faster to follow the connections.
I then proceed to pick a triangle and follow all the connected triangles. During this process I also build a bounding box, made form the minimum and maximum vertex values encountered by any triangle.
After that I use the built Axis Aligned Bounding Box to include all the triangles that cross it (triangle-AABB intersection). To be on the safe side, to make sure that I don’t miss clusters of triangles that are separated by a very thin line, I slightly enlarge the AABB before using it to collect the extra triangles crossing it.
This works fairly well in theory, but in practice something doesn’t work in some cases. Could be a logical bug or just a stupid bug 8)

Today I also wrote an array template ! I’ve even overloaded the [] operator. At its heart uses a function that I’ve been using for a long time to dynamically reallocate arrays. The function actually uses realloc rather than new and delete. This is potentially more efficient and generally more secure as I already keep my ‘C’-malloc functions wrapped for debug mode.

As I’m playing with vertices, I’m growing a doubt on wether it’s a good idea to keep separate vertices for cases in which triangles share a vertex at the same position but with different texture coordinates or normals. This is the best solution for real-time 3D rendering. But for intermediate processing, it seems like it could mean more trouble than good. In some cases it’s very useful to see which triangles share the same vertices. To keep everything tidy, I should have three different pools of data. The pool of position vertex data, the pool for texture coords and one for normals. At this point triangles will get 3 indices for each pool.
Data organized this way is not suitable for real-time, but it can be easily de-coupled to build data for real-time (one index per vertex, as opposed to three).

I need to think of this, and see really what’s the best solution !

Posted by Davide Pasca as Uncategorized at 12:58 AM EDT

2 Comments »

« Previous Entries