 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Renate Schaaf Guest
|
Posted: Tue Oct 11, 2005 8:36 am Post subject: ScaleDown |
|
|
Hi
I was wondering about the status of the ScaleDown project (scaling down
a bitmap). It looks only half started, but it would be nice to get a
competition going for this, as fast scaling routines come in very
handy. I see several problems though, e.g. concerning validation, the
signature of the routine and the actual algorithm used. Is there still
interest? I'd be willing to spend some time on the project setup, if so
desired. Don't know any Assembler, but I've been heavily fiddling
around with bitmap operations.
Renate
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Tue Oct 11, 2005 8:44 am Post subject: Re: ScaleDown |
|
|
Hi Renate
Yes this challenge is in an awfull state and has been forever.
I am very interested in having you volunteer to make the B&V.
What does the community say?
Best regards
Dennis
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Tue Oct 11, 2005 9:39 am Post subject: Re: ScaleDown |
|
|
| Quote: | What does the community say?
|
IIRC the main contention point was about how much imprecision and
approximation was allowed in a valid result, with some entries being
mathematically accurate, others mathematical approximations, and other
being just "good looking".
Basicly: different aims between being able to compute thumbnails as fast
as possible and being able to provide quality downsampling.
Eric
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Tue Oct 11, 2005 9:54 am Post subject: Re: ScaleDown |
|
|
Hi Eric
This is why we divided the challenge into two. 1 is named Low Quality := LQ.
The Other is named HQ
Regards
Dennis
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Tue Oct 11, 2005 1:01 pm Post subject: Re: ScaleDown |
|
|
In article <434b7ac2 (AT) newsgroups (DOT) borland.com>, Dennis wrote:
| Quote: | What does the community say?
|
Hi Dennis,
while waiting for reaction of the community, I'd still like to make a
suggestion right up front:
Change the form of the function
function ScaleDown(const SourceBitmap : TBitmap; ScaleFactor : Single)
: TBitmap;
into a procedure
procedure ScaleDown(const SourceBitmap, TargetBitmap : TBitmap;
ScaleFactor : Single);
Reasons:
1. Current form requires the coder to create the target bitmap, user
might forget to free the result.
2. User might create a bitmap, say Targetbitmap, then use code
Targetbitmap:=ScaleDown(....)
and not be aware that the memory/resource of the original Targetbitmap
is now orphaned.
3. Current form is unsuitable for inclusion in a try .. finally - block
for on the fly use of the result.
1 and 2 both happen in the BV-project as it is, so I guess the dangers
described are real, even with experienced users.
For other things, see reply to Eric.
Renate
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Tue Oct 11, 2005 1:01 pm Post subject: Re: ScaleDown |
|
|
In article <434b8684$1 (AT) newsgroups (DOT) borland.com>, Eric Grange wrote:
| Quote: | IIRC the main contention point was about how much imprecision and
approximation was allowed in a valid result
|
As far as I see all examples use average resampling
target=sum_SourceXMin^SourceXMax sum_SourceYmin^SourceYmax w_(ij)
source_(ij)
(hope my typing math is understandable)
with equal weights
w_(ij)=1/NumSourcePixels
NumSourcePixels=(SourceXMax-SourceXMin+1)*(SourceYMax-SourceYMin+1)
That's a good general algorithm to start with, I'd say. If that can be
sped up, then better algorithms can maybe follow. Problem is, depending
on how SourceXMin, SourceXMax etc. are defined in a particular
algorithm, the results can differ (among other things) by slight shifts
in pixels. For example, Dennis' routine uses the same matrix size all
over, whereas RMK uses differing matrix sizes, making sure to read in
any source pixel only once. I find it hard to think of a metric that
would notice that the two results are reasonably close. Right now, for
validation, I can think of 3 possible courses of action:
1. Discuss which is the best precise algorithm to be used, then
validate entries against a routine using that algorithm for exact
match. (Probably the fairest, and easiest to implement once the
discussion is over >:)
2. Come up with a number that measures closeness of results, allowing
for slight shifts (but which average out on the total). Only thing that
comes to my mind would be something like "convergence by measure": the
area in which the two bitmaps differ by more than a certain amount has
to be small. A recent post in Graphics suggests Fourier transforms,
that might also be a way, but isn't clear to me right now.
3. Forget validation. Maybe take votes thumbsup/down for each entry.
(Probably unfair)
Just some ideas, as I (happily) see that my post got some reaction.
Renate
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Tue Oct 11, 2005 1:31 pm Post subject: Re: ScaleDown |
|
|
Hi Renate
First I few things that I think I remember. I will follow up later with more
precision.
We have two ScaleDown challenges. Only the LQ is present at the web. No work
at all has been made on a B&V for the high quality challenge. It will be
based on the LQ B&V
I think we discussed properly and for a long time which function interface
to use and decided to use a procedure as you suggest.
My procedure is crap - please ignore it - delete it etc ;-)
The one by Eric is fine and can be used as reference in both challenges.
IMHO
In the LQ challenge we can allow some slack. This is coded in the validation
as a number each RGB component can be off. There also is a summed error
number that functions must be within (Summed with sign and then scaled
according to bitmap size)
Best regards
Dennis
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Tue Oct 11, 2005 2:06 pm Post subject: Re: ScaleDown |
|
|
| Quote: | As far as I see all examples use average resampling [...]
|
Not all of them ;)
| Quote: | That's a good general algorithm to start with, I'd say.
|
That's an approximation which is decent only when downsampling
a lot, so that partially overlapping source pixels contribution
is negligible.
The mathematically accurate version has to weight partially
overlapping source pixels differently or you'll get artefacts
whenever reducing to 20-99% of original size (approx, lower
bound depends on image of course).
If you want to downsample f.i. 640x640 to 512x512, proper
weighting of source pixels is a must, equal weighting can result
in atrocious image degradation if your source image isn't smooth.
| Quote: | 1. Discuss which is the best precise algorithm to be used, then
validate entries against a routine using that algorithm for exact
match. (Probably the fairest, and easiest to implement once the
discussion is over >
|
Fairest yes, but definetely not the easiest to implement... this is why
you commonly see source of the inaccurate "equal weighting" version
(though you won't see it in PhotoShop)
| Quote: | 2. Come up with a number that measures closeness of results
|
Square deviation is usually accepted: lots of errors of amplitude 1 on
color channels do not matter anywhere as much as a couple of misplaced
high amplitude deviations, as long as the errors aren't systematic
(ie. if you repeatedly a downsample, you shouldn't end up with a fully
white/black/grey/saturated image).
| Quote: | 3. Forget validation. Maybe take votes thumbsup/down for each entry.
(Probably unfair)
|
Will depend highly on source images...
Also, an approximated downsampling can be made to look "good" if you
introduce a sharpness filter (voluntarily or not), while a more accurate
version would be softer... yet the sharpening approximated downsampler
won't be suitable for use in a processing chain.
Eric
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Tue Oct 11, 2005 2:22 pm Post subject: Re: ScaleDown |
|
|
| Quote: | procedure ScaleDown(const SourceBitmap, TargetBitmap : TBitmap;
ScaleFactor : Single);
|
I would actually go a step further to
procedure ScaleDown(const SourceBitmap, TargetBitmap : TBitmap);
and have TargetBitmap's dimension be specified by the caller.
This for three extra reasons:
- it allows anisotropic downsampling
- it allows specifying target size accurately and unambiguously
- target bitmap's allocated memory is stable if it's already a DIB
Additionnally, having the routine support upsampling would be a nice
convenience (esp. when resampling is anisotropic).
Eric
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Wed Oct 12, 2005 7:24 am Post subject: Re: ScaleDown |
|
|
In article <434bc8f0$1 (AT) newsgroups (DOT) borland.com>, Eric Grange wrote:
| Quote: | I would actually go a step further to
procedure ScaleDown(const SourceBitmap, TargetBitmap : TBitmap);
|
Seems good to me. Or maybe even Mike Lischke's form from the GraphicEx
Stretch procedure
procedure ScaleDown(NewWidth, NewHeight: integer; const Source, Target:
TBitmap);
It's a bit more foolproof.
I'll be back for the harder things after I have seen all material, e.g.
your procedure which Dennis is mentioning.
Renate
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Wed Oct 12, 2005 7:24 am Post subject: Re: ScaleDown |
|
|
In article <434bbe4f$1 (AT) newsgroups (DOT) borland.com>, Dennis wrote:
| Quote: | We have two ScaleDown challenges. Only the LQ is present at the web.
The one by Eric is fine and can be used as reference in both challenges.
IMHO
|
I must be missing material then, I only have the things from the web, and
I cannot find a procedure by Eric. Could maybe someone post the missing
things to attachments?
Renate
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Wed Oct 12, 2005 7:39 am Post subject: Re: ScaleDown |
|
|
| Quote: | your procedure which Dennis is mentioning.
|
Couldn't find the old challenge code, so I just posted the adaptation
I now use in the attachments.
Eric
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Wed Oct 12, 2005 9:17 pm Post subject: Re: ScaleDown |
|
|
In article <434cbbe2$1 (AT) newsgroups (DOT) borland.com>, Eric Grange wrote:
| Quote: | Couldn't find the old challenge code, so I just posted the adaptation
I now use in the attachments.
|
Thanks, got it. I take it, yours is a real bilinear resampling algo,
with a triangle-shaped filter, not a box-resampling one, as the others
I described. I can't figure out your precise algorithm right now, as
the ASM is a bit of a black box for me at the moment , but maybe with
time and a little help.
I've made a test-application to point out the problems faced with
validation, it's being uploaded to attachments. I compared results of
test algorithms to the result of photoshop bilinear resampling. I've
included routines from Mike Lischke's GraphicEx as a reference. Also,
your routine and RMK and my own (similar), but the latter two actually
lower quality box resampling.
Anyway, your routine comes closest to photoshop, but still isn't
identical, which in my opinion doesn't matter that much, it's a great
looking algorithm and quite fast. But how to come up with a
number/limit for validation is even less clear to me now. For example,
GraphicExTriangle is also a (mathematically valid, I guess) bilinear
resampling routine, but is seems to have shifts versus photoshop,
causing the square distance to shoot up, a lot maybe, depending on the
picture.
LQ=Box-Resampling
HQ=Bilinear and better?
What about the real low-quality Delete_Scans, used by
TImage.stretch=true? That also comes in handy when time is really
pressing, and can be made faster, too.
Enough rambling,
Good night
Renate
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Wed Oct 12, 2005 9:56 pm Post subject: Re: ScaleDown |
|
|
Sorry, I couldn't upload the project, too large, need to change the
size of bitmaps included.
Renate
|
|
| Back to top |
|
 |
Renate Schaaf Guest
|
Posted: Wed Oct 12, 2005 10:35 pm Post subject: Re: ScaleDown |
|
|
Now in attachments.
Renate
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|