在圖像編碼的算法中,需要將一個給定的方形矩陣進行Z字形掃描(Zigzag Scan),以獲得更好的壓縮比。給定一個n×n的矩陣,Z字形掃描的過程如圖所示:
經(jīng)過掃描后得到的數(shù)據(jù)結(jié)果為:
57 | 45 | 0 | 23 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | -30 | 1 | 0 | 0 | 0 | 0 | 0 |
-16 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
(1)行程編碼壓縮最壞情況下,數(shù)據(jù)壓縮后數(shù)據(jù)元素的數(shù)量將是原來的
2
2
倍。(2)根據(jù)上述掃描算法,其 VB 代碼實現(xiàn)如下,請在橫線處填入合適的代碼。
Dim a(0 To 1000)As Integer'存儲原矩陣數(shù)據(jù),按行優(yōu)先存儲
Dim b(0 To 1000)As Integer'存儲Z形掃描后數(shù)據(jù)
Dim c(0 To 1000)As Integer'存儲行程編碼壓縮后數(shù)據(jù)
Dim n As Integer
‘矩陣導(dǎo)入代碼略,以行優(yōu)先存儲在a數(shù)組中,如例子中數(shù)據(jù)存儲順序為“57,45,0,23,0,0…”
Private Sub Command2_Click
( ?。?/div>
Dim choice As Integer'1:向右移動;2:向右上移動;3向下移動 4向左下移動
Dim row As Integer,col As Integer,i As Integer,j As Integer
Dim pre As Integer,count As Integer
choice=1:row=0:col=0:i=0
Do While (row<>n-1 Or col<>n-1)
b(i)=a(row*n+col):i=i+1
If choice=1 Then
①
If row=0 Then choice=4 Else choice=2
ElseIf choice=2 Then
row=row-1:col=col+1
If ②
choice=1
ElseIf col=n-1 Then
choice=3
End If
ElseIf choice=3 Then
row=row+1
If col=0 Then choice=2 Else choice=4
ElseIf choice=4 Then
row=row+1:col=col-1
If row=n-1 Then
choice=1
ElseIf col=0 Then
choice=3
End If
End If
Loop
b(i)=a(n*n-1):j=0:pre=b(0):count=0
For i=0 To n*n-1'輸出Z形序列,并進行行程壓縮
If pre=b(i) Then
count=count+1
Else
c(j)=pre:c(j+1)=count
③
pre=b(i):j=j+2
End If
Next i
c(j)=pre:c(j+1)=count
Text1.Text=““
For i=0 To j+1
Text1.Text=Text1.Text+Str(c(i))+“,“
Next i
End Sub
( )
Dim choice As Integer'1:向右移動;2:向右上移動;3向下移動 4向左下移動
Dim row As Integer,col As Integer,i As Integer,j As Integer
Dim pre As Integer,count As Integer
choice=1:row=0:col=0:i=0
Do While (row<>n-1 Or col<>n-1)
b(i)=a(row*n+col):i=i+1
If choice=1 Then
①
col=col+1
col=col+1
If row=0 Then choice=4 Else choice=2
ElseIf choice=2 Then
row=row-1:col=col+1
If ②
row=0Andcol<>n-1
row=0Andcol<>n-1
Thenchoice=1
ElseIf col=n-1 Then
choice=3
End If
ElseIf choice=3 Then
row=row+1
If col=0 Then choice=2 Else choice=4
ElseIf choice=4 Then
row=row+1:col=col-1
If row=n-1 Then
choice=1
ElseIf col=0 Then
choice=3
End If
End If
Loop
b(i)=a(n*n-1):j=0:pre=b(0):count=0
For i=0 To n*n-1'輸出Z形序列,并進行行程壓縮
If pre=b(i) Then
count=count+1
Else
c(j)=pre:c(j+1)=count
③
count=1
count=1
pre=b(i):j=j+2
End If
Next i
c(j)=pre:c(j+1)=count
Text1.Text=““
For i=0 To j+1
Text1.Text=Text1.Text+Str(c(i))+“,“
Next i
End Sub
【考點】應(yīng)用程序的試運行和保存.
【答案】2;( ?。?;col=col+1;row=0Andcol<>n-1;count=1
【解答】
【點評】
聲明:本試題解析著作權(quán)屬菁優(yōu)網(wǎng)所有,未經(jīng)書面同意,不得復(fù)制發(fā)布。
發(fā)布:2024/4/20 14:35:0組卷:0引用:1難度:0.5
相似題
-
1.大部分社交軟件都有好友推薦的功能,當(dāng)用戶 A 和用戶 B 的共同好友數(shù)量超過閾值 p 時,由系統(tǒng)向用戶 A 推薦用戶 B。
編寫 VB 程序,實現(xiàn)好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關(guān)系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖:
(1)根據(jù)如圖所示數(shù)據(jù),若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為:
(2)實現(xiàn)上述功能的 VB 程序如下,請在橫線處填入合適的代碼。發(fā)布:2025/1/2 10:30:2組卷:0引用:1難度:0.3 -
2.某學(xué)校開展了藝術(shù)節(jié)活動,數(shù)組a中存儲了n個節(jié)目的編號和得分數(shù)據(jù),數(shù)組存儲結(jié)構(gòu)如圖所示:
小明使用選擇排序思想對上述n個節(jié)目按得分進行降序排序(得分相同的按編號升序排列),并依據(jù)得分插入各個節(jié)目的排名信息,處理后數(shù)組a的存儲結(jié)構(gòu)如圖所示:
程序運行時,單擊命令按鈕Command1后讀取數(shù)據(jù)到數(shù)組a中并顯示在列表框List1中,單擊命令按鈕Command2后將節(jié)目按照上述規(guī)則進行排序,并將排名結(jié)果顯示在列表框List2中。
實現(xiàn)上述功能的VB程序如下,請回答下列問題:
(1)已知窗體名稱為Forml,要使程序加載時,窗體標題自動顯示為“第15題程序”,則可在
(2)請在橫線處填入合適的代碼。
(3)加框處代碼有誤,請改正。發(fā)布:2025/1/2 10:30:2組卷:0引用:1難度:0.3 -
3.小明用python語言中對大小為100*100像素的圖像“上.jpg”(如圖所示)進行簡單處理,部分代碼如圖:
程序執(zhí)行后的圖像效果是( )發(fā)布:2024/12/20 9:30:2組卷:3引用:5難度:0.4
APP開發(fā)者:深圳市菁優(yōu)智慧教育股份有限公司| 應(yīng)用名稱:菁優(yōu)網(wǎng) | 應(yīng)用版本:5.0.7 |隱私協(xié)議|第三方SDK|用戶服務(wù)條款
本網(wǎng)部分資源來源于會員上傳,除本網(wǎng)組織的資源外,版權(quán)歸原作者所有,如有侵犯版權(quán),請立刻和本網(wǎng)聯(lián)系并提供證據(jù),本網(wǎng)將在三個工作日內(nèi)改正