全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1455
推到 Plurk!
推到 Facebook!

請問這個程式處理圖像的方式

缺席
ladese05
一般會員


發表:3
回覆:2
積分:1
註冊:2006-09-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-06-01 16:27:28 IP:203.67.xxx.xxx 訂閱
各位大大們好,這隻程式是這裡的前輩們所寫的,內容是關於DCT
但是程式的內容有個地方我一直不能理解
在處理圖像跑迴圈的地方,大致如下
[code cpp]
for(Countx=0;Countx < PictureWidth;Countx )
for(County=0;County < PictureHight;County )
[/code]
是這種方式,先處理高度,在寬度。
這樣子處理,圖沒有問題...
array存的方式以及圖像處理的方式我想不通

我曾試著改成由左至右,由上而下的方式處理
將Hight放在外面,但總是改不出正常的圖形...
不曉得我觀念錯在哪...T_T

請問有前輩們能幫小弟解惑嗎?
麻煩了...
謝謝

這個程式大約如下
[code cpp]
#include <math.h><br />#include
#include
#pragma hdrstop
#include "SEGment.h"
#define Matrix_N 8.0
#define Pi 3.141592654
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
complex Oper_Array_copm[8][8];
complex Conj_Oper_Array_copm[8][8];
complex Buff_Array_copm1[8][8],Buff_Array_copm2[8][8];
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(OpenPictureDialog1->Execute()==true)
{ //開檔並載入圖形
openfile=OpenPictureDialog1->FileName;
Image1->Picture->LoadFromFile(openfile);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
operationflag=false; //初始化
Label1->Caption= TrackBar1->Position;
ComboBox1->ItemIndex=0; //預設值為哪個
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Form1->Close(); //結束程式
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if( SaveDialog1->Execute()==true) //輸出入圖存檔
{
savefile=SaveDialog1->FileName;
Image2->Picture->SaveToFile(savefile);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Computer_Answer_Matrix() //Matrix計算
{
int PictureHight,PictureWidth,CountBx,CountBy,Countx,County,Countz;
double answer;
complex Canswer;
PictureHight=Image1->Picture->Height/8;
PictureWidth=Image1->Picture->Width/8;
// 轉換
for(CountBx=0;CountBx < PictureWidth;CountBx )
for(CountBy=0;CountBy < PictureHight;CountBy )
{
for(Countx=0;Countx<8;Countx )
for(County=0;County<8;County )
{
answer=0;
for(Countz=0;Countz<8;Countz )
answer=answer Oper_Array[Countx][Countz]*Picture[CountBx*8 Countz][CountBy*8 County];
Test_Array[Countx][County]=answer;
}
for(Countx=0;Countx<8;Countx )
for(County=0;County<8;County )
{
answer=0;
for(Countz=0;Countz<8;Countz )
answer=answer Test_Array[Countx][Countz]*Oper_Array[County][Countz];
bufferarray[Countx][County]=answer;
if(ComboBox1->ItemIndex==0) //輸出為轉換後之矩陣
{
Result[CountBx*8 Countx][CountBy*8 County]=int(answer);
}
}
//保留N*N,其餘為零
for(Countx=0;Countx<8;Countx )
for(County=0;County<8;County )
if(( Countx >= (TrackBar1->Position))|(County >= (TrackBar1->Position)))
bufferarray[Countx][County]=0;
// 反轉換
if(ComboBox1->ItemIndex==1)
{
for(Countx=0;Countx<8;Countx )
for(County=0;County<8;County )
{
answer=0;
for(Countz=0;Countz<8;Countz )
answer=answer Oper_Array[Countz][Countx]*bufferarray[Countz][County];
Test_Array[Countx][County]=answer;
}

for(Countx=0;Countx<8;Countx )
for(County=0;County<8;County )
{
answer=0;
for(Countz=0;Countz<8;Countz )
answer=answer Test_Array[Countx][Countz]*Oper_Array[Countz][County];
if(answer>255)answer=255; //矩陣值大於255則為255
if(answer<0)answer=0; //矩陣值大小於0則為0
Result[CountBx*8 Countx][CountBy*8 County]=answer;
}
}
}
Drawanswer(1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Drawanswer(int flag)
{
int PictureHight,PictureWidth,Countx,County;
int colorvalue;
//輸出與輸入圖形繪出
PictureHight=Image1->Picture->Height;
PictureWidth=Image1->Picture->Width;
for(Countx=0;Countx < PictureWidth;Countx )
for(County=0;County < PictureHight;County )
{
switch(flag)
{
case(0):
colorvalue =(int)Picture[Countx][County];
SetPixel(Image1->Canvas->Handle,Countx,County,TColor(RGB(colorvalue,colorvalue,colorvalue)));
break;
case(1):
colorvalue =(int)Result[Countx][County];
SetPixel(Image2->Canvas->Handle,Countx,County,TColor(RGB(colorvalue,colorvalue,colorvalue)));
break;
}
}
Image1->Refresh();
Image2->Refresh();
operationflag=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender) //執行鈕
{
Image2->Picture->LoadFromFile(openfile);
Computer_Operation_Matrix(); //轉換矩陣計算
Computer_Answer_Matrix(); // 矩陣換算
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Computer_Operation_Matrix()
{
int Countx,County,Countz;
double answer,buffer_f,alpha1,alpha2;
double buffer_i;
//make a decision for elments(i,j) of Matrix
complex compf(0.0,-1.00);
complex compf2(0.0,1.00);
for(Countx=0;Countx for(County=0;County {
if(Countx==0)
alpha1= 1.0/sqrt(2.0);
else
alpha1=1.0;
answer=double(Pi*(County 0.5)*Countx/(Matrix_N));
buffer_f=cos(answer);
buffer_i=sqrt(2.0/(Matrix_N));
answer=buffer_i*buffer_f*alpha1;
Oper_Array[Countx][County]=answer; //轉換Matrix
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender) // 灰階化/載入 鈕
{
int PictureHight,PictureWidth,Countx,County;
int colorvalue;
PictureHight=Image1->Picture->Height; //height of image
PictureWidth=Image1->Picture->Width; //Width get information of image for Loop
for(Countx=0;Countx < PictureWidth;Countx )
for(County=0;County < PictureHight;County )
{
colorvalue=GetPixel(Image1->Canvas->Handle,Countx,County);
Picture[Countx][County]=( GetRValue(colorvalue) * 77.0 //R*0.3*256
GetGValue(colorvalue) * 151.0 //G*0.57*256
GetBValue(colorvalue) * 28.0)/256.0; //B*0.13*256
}
Drawanswer(0); //draw gray image on input image area
}
[/code]
編輯記錄
ladese05 重新編輯於 2008-06-01 16:29:10, 註解 無‧
ladese05 重新編輯於 2008-06-01 16:30:31, 註解 無‧
ladese05
一般會員


發表:3
回覆:2
積分:1
註冊:2006-09-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-06-05 14:28:13 IP:140.136.xxx.xxx 訂閱
我瞭解了...
原來是因為SetPixel的關係
如果高要放在外面
SetPixel的部份指定 Countx 和 County 的地方要對調
才能正確顯示
系統時間:2024-12-05 3:33:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!