It looks like you're new here. If you want to get involved, click one of these buttons!

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 628 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

mydelphi
Member Posts: **62**

I need help writing the coding part to calculate the DCT

(discrete cosine transfer) of an 8x8 matrix. Can some kind

person walk me through this Pascal coding process, please.

I found this page, and I want to use it as a reference for

checking my work, by copying the image in it, and using it

as the reference, as well as the QMx quantization numbers

for each, in my completed and working DCT model. I was

able to screen copy the color image of the birds. Now, to

set up the rest of the process.

http://www.cs.sfu.ca/CC/365/li/interactive-jpeg/Ijpeg.html

And, here is a webpage that helps to describe DCT:

http://www.nationmaster.com/encyclopedia/JPEG

Here's my detail plea.

I've searched the internet, but all I find is c/c++ or java

code pieces, and are enhanced or designed to be fast, but

they are too complex follow and understand.

What I would like, is to have something that is in the

most basic of simple way possible. Speed is not important

here. I want to understand and learn this DCT process.

So, if speed could be overlooked for now, while I learn

this first, I would really appreciate it.

I have tons and tons of info on DCT from all over the web

that I copied to my harddrive. Many are pdf, docs, ppt,

and txt files. They go on to describe the nature or process

of DCT, but it lacks one thing. Simplicity. The proper

expression in Pascal format is missing. Everything is in

c/c++ and too cryptic to follow. And because of this, I

can't go further without actual code to work with.

What I would like, is the proper formula in a Pascal syntax

that caculates DCT for the filled in rgb[8,8] data, and then

with the calculated DCT values, fills another matrix called

dct[8,8]. This matrix will now have the dct[8,8] values.

(My next step will be to Quantize this dct[8,8] with a

quant[8,8] matrix, and further on)

(I do know how to caluclate the Quantization, however)

Lets say I have a 512x512 image, and I read in all the RGB

pixel values into rgb[8,8] with the code:

[code]

var

rgb : array[0..8-1, 0..8-1] of double;

r,c : integer;

.

.

begin

// read in pixles, starting at top, left image

// area, i.e., rgb[0,0]..

for r:=0 to 8-1 do begin

for c:=0 to 8-1 do begin

rgb[r,c] := imabe1.canvas.GetPixels[r,c];

end;

end;

// fills rgb[8,8] matrix with pixels numbers

// looking like this, (but with actual real numbers.

// the 000's are just to show what I'm describing

// below. I guess I am thinking in the range of

// 0-255, but I realize that I defined my rgb[8,8]

// array matrix as Double's.

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

end;[/code]

Here is some code that I found, and converted from c/c++

to Pascal, but it uses a pre-lookup table which I don't

need at this time. I need the long way of coding it in

one line, for now. In Pascal, the syntax is suppose to be

cos(x) right? But,

[code]

B[k1,k2] := B[k1,k2] + ( A[i,j] * (cosine[k1,i] * cosine[k2,j]) );

if (k1 = 0) then Cu := SQRT2o2 else Cu := 1.0;

if (k2 = 0) then Cv := SQRT2o2 else Cv := 1.0;

B[k1,k2] := B[k1,k2] * (0.25 * Cu * Cv);

[/code]

This line is using a lookup table of precalculated cosine numbers:

[code] B[k1,k2] := B[k1,k2] + ( A[i,j] * (cosine[k1,i] * cosine[k2,j]) );[/code]

But I am really looking for the longer way of doing it, and

without a lookup table, so that I understand the whole process

of calculating DCT.

I did find another reference to calculating DCT, but I don't

understand it here:

[0006]

DCT[v][u] = 1/4xCu.Cv. SIGMA SIGMA F[y][x].cos((2x+1)u pi

/16).cos((2y+1)v pi /16)

Cu, Cv = 1/2(u,v = 0), 1(otherwise)

My goal is to write several functions to do calculations

and things, with the following routines to make things

easier to work with on a procedure/function base, in

the order of DCT process:

1-Procedure fillRGBregion();

2-Procedure rgb_to_YUV();

3-Procedure reduceto128Values(); does a (num[r,c]-128)

4-Procedure calculateDCT();

5-Procedure calculateQuantization();

I believe the above is the right order of obtaining DCT, but

I'm not sure of the -127 to +128 routine. Where exactly is this

suppose to happen. It's use is for shifting by 128 and THEN

doing the DCT part.

Later, I plan on enhancing the speed of the DCT algorithem

process. I just need to get it working for now

-mydelphi

(discrete cosine transfer) of an 8x8 matrix. Can some kind

person walk me through this Pascal coding process, please.

I found this page, and I want to use it as a reference for

checking my work, by copying the image in it, and using it

as the reference, as well as the QMx quantization numbers

for each, in my completed and working DCT model. I was

able to screen copy the color image of the birds. Now, to

set up the rest of the process.

http://www.cs.sfu.ca/CC/365/li/interactive-jpeg/Ijpeg.html

And, here is a webpage that helps to describe DCT:

http://www.nationmaster.com/encyclopedia/JPEG

Here's my detail plea.

I've searched the internet, but all I find is c/c++ or java

code pieces, and are enhanced or designed to be fast, but

they are too complex follow and understand.

What I would like, is to have something that is in the

most basic of simple way possible. Speed is not important

here. I want to understand and learn this DCT process.

So, if speed could be overlooked for now, while I learn

this first, I would really appreciate it.

I have tons and tons of info on DCT from all over the web

that I copied to my harddrive. Many are pdf, docs, ppt,

and txt files. They go on to describe the nature or process

of DCT, but it lacks one thing. Simplicity. The proper

expression in Pascal format is missing. Everything is in

c/c++ and too cryptic to follow. And because of this, I

can't go further without actual code to work with.

What I would like, is the proper formula in a Pascal syntax

that caculates DCT for the filled in rgb[8,8] data, and then

with the calculated DCT values, fills another matrix called

dct[8,8]. This matrix will now have the dct[8,8] values.

(My next step will be to Quantize this dct[8,8] with a

quant[8,8] matrix, and further on)

(I do know how to caluclate the Quantization, however)

Lets say I have a 512x512 image, and I read in all the RGB

pixel values into rgb[8,8] with the code:

[code]

var

rgb : array[0..8-1, 0..8-1] of double;

r,c : integer;

.

.

begin

// read in pixles, starting at top, left image

// area, i.e., rgb[0,0]..

for r:=0 to 8-1 do begin

for c:=0 to 8-1 do begin

rgb[r,c] := imabe1.canvas.GetPixels[r,c];

end;

end;

// fills rgb[8,8] matrix with pixels numbers

// looking like this, (but with actual real numbers.

// the 000's are just to show what I'm describing

// below. I guess I am thinking in the range of

// 0-255, but I realize that I defined my rgb[8,8]

// array matrix as Double's.

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

// 000 000 000 000 000 000 000 000

end;[/code]

Here is some code that I found, and converted from c/c++

to Pascal, but it uses a pre-lookup table which I don't

need at this time. I need the long way of coding it in

one line, for now. In Pascal, the syntax is suppose to be

cos(x) right? But,

[code]

B[k1,k2] := B[k1,k2] + ( A[i,j] * (cosine[k1,i] * cosine[k2,j]) );

if (k1 = 0) then Cu := SQRT2o2 else Cu := 1.0;

if (k2 = 0) then Cv := SQRT2o2 else Cv := 1.0;

B[k1,k2] := B[k1,k2] * (0.25 * Cu * Cv);

[/code]

This line is using a lookup table of precalculated cosine numbers:

[code] B[k1,k2] := B[k1,k2] + ( A[i,j] * (cosine[k1,i] * cosine[k2,j]) );[/code]

But I am really looking for the longer way of doing it, and

without a lookup table, so that I understand the whole process

of calculating DCT.

I did find another reference to calculating DCT, but I don't

understand it here:

[0006]

DCT[v][u] = 1/4xCu.Cv. SIGMA SIGMA F[y][x].cos((2x+1)u pi

/16).cos((2y+1)v pi /16)

Cu, Cv = 1/2(u,v = 0), 1(otherwise)

My goal is to write several functions to do calculations

and things, with the following routines to make things

easier to work with on a procedure/function base, in

the order of DCT process:

1-Procedure fillRGBregion();

2-Procedure rgb_to_YUV();

3-Procedure reduceto128Values(); does a (num[r,c]-128)

4-Procedure calculateDCT();

5-Procedure calculateQuantization();

I believe the above is the right order of obtaining DCT, but

I'm not sure of the -127 to +128 routine. Where exactly is this

suppose to happen. It's use is for shifting by 128 and THEN

doing the DCT part.

Later, I plan on enhancing the speed of the DCT algorithem

process. I just need to get it working for now

-mydelphi

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.