Texturizer

Discuss the Wing Commander Series and find the latest information on the Wing Commander Universe privateer mod as well as the standalone mod Wasteland Incident project.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

BINGO. That's correct. How did you tell? The only feature by which I can identify the enlarged and reduced one is the dimmer eye glints; --a problem that's proven pretty hard to fix and remains a high priority, btw.
hurleybird
Elite
Elite
Posts: 1671
Joined: Fri Jan 03, 2003 12:46 am
Location: Earth, Sol system.
Contact:

Post by hurleybird »

chuck_starchaser wrote:BINGO. That's correct. How did you tell?
The second one is just a little bit less sharp overall, which is going to happen when you smooth the picture blowing it up. The eye glints were a bit of a giveaway, as were the gold clips (which I actually like better), but the blurry ears was the main one.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Another bug bites the dust.
Another bug bites the dust.
Another bug and another bug,
Another bug bites the dust.

Image

Yeah!

There are still more bugs lurking around, tho...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Another bug found and killed... Stupid one; a missing pair of parenthesis.
Doing much better with the eyes:

Image

Image

But notice there's still a sharp-cornered pixel on the side of the nose, a bit towards the eye. And another sharp one on the side of the nostril. Don't know where the heck those are coming from...
But this is getting pretty close to good enough for me. I like the hair, specially. Much cleaner than before.

Image

Just wish I could figure out why I can't seem to get better contrast and sharpness with the fabric of the jacket...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Found that last bug. Well, sort of; I know what to tweak to get rid of it, though not exactly what causes it.
Anyways, the next feature to add is going to take some time. I need to make my filters --anisotropic or othewise-- "chroma-aware". The problem of bluish edges on the shirt stems from the sharpening cells of the filters. It's like this: A matrix is applied, with weights. Say a 4x4, 45 degree, anisotropic matrix looks like this:

Code: Select all

float Aniso4Flt045[16] =
{
	-1.0f, -1.4f, +1.0f, +1.4f,
	-1.4f, +1.0f, +3.0f, +1.0f,
	+1.0f, +3.0f, +1.0f, -1.4f,
	+1.4f, +1.0f, -1.4f, -1.0f
};
So, the main diagonal multiplies corresponding color values along a 45 degree line on the texture, causing like a blur in that direction, and sharpening to the sides (negative values). I only choose a 45 degree matrix if I detected a 45 degree line or edge, of course. But what happens across that line? Well, if the material to the top left is dark, it causes brightening at the bottom right. So far so good. but now, what happens if the top left is orange and the bottom right is grey? What happens is that the sharpening becomes chromatic. The opposite of orange is blue.
So, to avoid this, I need my filtering routines to measure chromatic distance, probably square it, and use it to divide the weight of that cell of the matrix before multiplication. But the problem is that, right now, the way the code is, I can't add chromatic awareness to the filters, because my texture matrix has a single float number per cell... I initialize my matrices with one color at a time. So I need a new matrix class for colors, with four floats per cell, for red, green, blue and alpha. And then add chroma awareness... And change the code everywhere...

And after that, the next thing will be to compute my matrices procedurally.
Right now, to produce a 22.5 degree matrix I blend a 0 degree and a 45 degree matrices, and renormalize the new matrix. But this doesn't work very well for 5x5 anisotropic matrices without making the central blurring bars too thick: If you blend two 5x5 matrices with a vertical line and a 45 degree line together, you don't get a line inbetween; you just get two lines. And I need ultra-thin blur line matrices of variable angles, to make good edges...

Anyways, one more update for now. Frankly, I don't see much of a difference, but the change is rather radical. I gamma-corrected the whole picture before processing, and the de-gammaed it back before writing it down. Should have increased sharpness at the low end, like for the jacket; but I don't notice any improvement.

Image
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

With chroma-aware filters:

Image

Next is procedural matrices...
hurleybird
Elite
Elite
Posts: 1671
Joined: Fri Jan 03, 2003 12:46 am
Location: Earth, Sol system.
Contact:

Post by hurleybird »

Awesome! The gradients look so much smoother now.

The ears became a blurry mess for some reason though.
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

Indeed, the ears' outside looks green to me... but perhaps it's just my display.
But apart from this, what you're doing looks great, chuck.

About the jacket: I know you code checks for lines and corners etc. But do you check for simple patterns like 'striped' or 'checkered'? This could probably improve the jacket's pattern.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

@hurleybird:
Indeed, the gradients are smoother, but the way I got that was not really a bug fix, or even the chromatic awareness in the filters, which I came to realise later, isn't even working at all. Rather a workaround I found to a bug that's still there, by simply applying the same anisotropic solution to the whole thing. See below...

@Zeog:
My algorithm looks for lines only, not corners. But I had a smooth blend between two algorithms: anisotropic and "bicubic". Works like this: I have 4 detection matrices for lines, and 4 for edges, at 0, 45, 90 and 135 degrees. The intensity of matching intensities of line and edge detection for each angle are added together, so I end up with four quantities for each pixel. I write these to an internal plane of four floats per pixel. Then I apply a blur pass to this internal plane, to reduce angular noise. Now, what I was doing was judging the "strength" of line detection by sorting the four numbers, subtracting the lower from the higher, and dividing by the sum.
Then, to filter the image as I interpolate, I have anisotropic filters at 0, 45, 90 and 135 degrees also, so I take the intensities of the two strongest detections and use those numbers to create a final matrix by blending two of the model anisotropic matrices. But I also computed a bicubic filtering, and I blended the two results based on the strength of the line detection.
This actually never worked, tho. And this last image has a hack where I override strength of line detection, making it equal to 1. But the reason why it never worked may be a bug I've yet to find.
As for the jacket, the problem is that my filters turn sharpening into blurring at low contrasts. My filters are quite complicated, really. Sort of like Gimp's "selective blur", but using a continuous function that turns sharpening into blurring at the lowest contrasts, then to neither at a contrast of abut 16 units (out of 256), then rises to full sharpening by about 90 contrast, and falls again to no sharpening at full contrast. Got best results that way. Doing this for each cell of a 5x5 matrix, for each pixel. Little wonder it takes 30 seconds... Anyways, back to the jacket: The contrast there is low. And therefore it gets blurred. But if I change that, then the face starts getting acne.
Another thing I think I'll try is taking the log of the luma. Right now, I'm computing luma in a preprocessing stage, and writing it to the alpha channel. but maybe if I compute the log of it, the contrast in the jacket will increase, while leaving the face contrast neutral. On the other hand, I don't want to make this into an algorithm that only works for Lynch :D
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Very marginal improvement. I got the chromatic discrimination factor working with the filters. The only difference it makes is with the former bluish halo on the edge of the shirt collar; but my eyes can't even see the difference at one to one; I see the difference very clearly at 4:1 zoom; but I post it just in case someone else's eyes are better than mine. :) In any case, this is more correct than the former, and big jurneys are made of many small steps, so the chroma discriminator is there to stay.

Image
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Another hard to see improvement, though even drastic. I finally managed to find where the problem with the non-anisotropic filter happens. It was with the 3x3 sharpening matrix. The 5x5 sharpening matrix works fine. So I disabled the 3x3 matrix, and I re-enabled the line detection strength based blending of anisotropic and non-anisotropic filtering...

Image
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

The best solution, though, will be to implement procedural filters, so for each pixel I'd procedurally create a new, 5x5 filtering matrix with an elliptycal pattern of weights, where the angle matches the exact angle of line detection, and the aspect ratio of the ellipse is controlled by the strength of the line detection. Then I could get rid of all these blendings... I'm not too sure about the math; need to go somewhere with a notebook, a pen, a calculator, and order an extra large capuccino.
charlieg
Elite Mercenary
Elite Mercenary
Posts: 1329
Joined: Thu Mar 27, 2003 11:51 pm
Location: Manchester, UK
Contact:

Post by charlieg »

If you can pull this off, you'll be providing an amazing gift to the free software community. Just think of all the older projects that could go from lo-res to hi-res with a bit of processing work..... it would be amazing.

Go get that coffee and get to work. ;)
Free Gamer - free software games compendium and commentary!
FreeGameDev forum - open source game development community
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Thanks, yeah, I think this is going to make an impact or two out there. I have quite a few things to fix besides the procedural matrices, though: Right now it requires the originals to be square and a power of two size, and it doesn't handle alpha channel. All fixable things, though; and then a friend of mine will then try to make it compile in *nix. Right now it's windows only. I also need to add a bit automatic contrast stretching, a despeckling pre-processing pass, and for it to be able to scale textures in batch mode, so that you can pass it a folder or folder tree as argument, and leave it running all night, doing all the pics at once. But right now I'd better do some work for my day job, before I get fired... :D
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

Perhaps it went unnoticed: when you introduced the chroma aware filters at the beginning of this page the ears are now being definitely dark green at the side where they touch the background!
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

My monitor is getting old, and right now I have too much sunlight coming in, but I'll check that out tonight. Thanks.
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

I have attached a sample in which I intensified the brightness of that unnatural hue to indicate where the problem areas are. It really is a dark green which blends between dark grey and dark orange.
You do not have the required permissions to view the files attached to this post.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Ah, I see it now. Very interesting: The greenness is not IN the ear, it's in the background. The grey background turned to green as a result of sharpening off pixels in the ear. But it looks like as if it were part of the ear because, in a couple of places, the ear got extended with the same color. So my chroma discriminator is not working. This is precisely what it was supposed to prevent happening. The reason the ear's own color sometimes leaks out onto the background, and sometimes its complement (green), is that curve I was describing in an earlier post: The anisotropic filters have positive weights (for blurring) and negative weights (for sharpening), but my funny curve function turns the sharpening gain down as the luminosity contrast decreases, and even reverses the sign, turning the sharpening weights into blurring weights, for very low contrasts. But this only looks good across similar chromatic hues and saturations, so the chromatic discriminator was going to detect chromatic distance and simply turn those sharpening/blurring gains to zero if the colors were different. But obviously it's still not working...

Thanks for catching this. I was only looking at the edge of the shirt's collar before; but this is a much better test location.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Alright, found it...

Image

The problem was nowhere near where I thought it was. When I changed from using scalar matrices (one matrix per color channel) to vector (full color) matrices, I had some value clamping safeties that had to be translated to color clamping. So I defined a "<" (less than) operator for color, which, for lack of a better idea, I made it based on luminance comparisons. But when the test didn't pass I assigned the whole color to the "min" and "max" colors, so I could end up with a "max color" like 255,255,0. So, if the result of the matrix was, say, 30, 30, 30, it would then get clamped to (30, 30, 0) RGB. So I changed to using per-color clamps, and problem solved.

If Zeog hadn't mentioned it, I would probably never have seen the problem, with my monitor.

The bad news now is that my chroma discriminator is still not working at all... Worse than that, I can't seem to get any logs out of it... Looks as if it never engages...

EDIT: I just noticed while comparing to earlier shots, this bug had been causing artifacts in the eyes, that I was wondering about for a while, like horizontal archs across the eyeballs...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Sorry; once again, the chroma discriminator WAS working; just my way of testing it was erroneous. But I tried squaring and cubing it and it makes little difference, and begins to make some artifacts. Won't bother showing them. But having it straight (without squaring) is a visible improvement over not having it at all. Anyways, back to work on procedural matrices while I go for dinner before the restaurant closes.
GoldenGnu
Bounty Hunter
Bounty Hunter
Posts: 155
Joined: Fri Jan 27, 2006 6:58 pm
Location: Denmark

Post by GoldenGnu »

very interesting thread 8)
Image
VSTrade - A Merchants Guide to Intergalactic Trading!
0.3.0.0 Stable (3 july 2008)
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Thanks. Gone through gallons of coffee already, though, and a solution for making filters procedurally is still eluding me... Was working on it last night while dining at my favorite Mauritian restaurant, and the owner got on my case about "relaxing" and "enjoying life"... I think I'll go for Vietnamese tonight...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Finally!
Boy I'm rusty in math.
Took me ages to work out the formulas.

For any matrix, of any number of cells, and
1) where distances are measured from the center in cell-spacing units
2) where I have three input constants
2a) X being a strength of line detection along X axis
2b) Y a strength of line detection along Y axis
2c) A is a degree of desired anisotropy, from 0 for a radial blur to 1 for a straight line
3) and where I have 2 variables
3a) x being the location in the x axis of a center of a cell, (or any point for that matter)
3b) y the location in y

The non-normalized coefficient for that cell is:

Code: Select all

k = 1 / { (1+A)*(Xy-Yx)^2/(X^2+Y^2) + (1-A)*[x^2+y^2-(Xy-Yx)^2/(X^2+Y^2)] }
By "normalizing" I mean going through all the coefficients and add offsets and scaling factors so as to have negative coefficients adding to -1, and positive coefficients adding up to +2.

Now it's down to coding it...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Just an update, and to say I haven't abandoned this project at all. This evening I finished writing the pseudo-code on paper. I'll probably code it in and start compiling next weekend.
Post Reply