UVA - 806 Spatial Structures

53 篇文章 1 订阅

题目大意:
用四叉树可以表示黑白图像,对于一个黑白图像等分四部分,左上、右上、左下、右下。如果一个区域同为一种颜色,那么就不再分叉。现在从根节点开始,走左上记1、右上记2、左下记3、右下记4。一个节点的路径就可以用这些数连起来构成一个五进制的数。输入有两种情况,一种是给nn的0/1点阵,输出所有黑色节点的路径(10进制);一种是给出黑色节点的路径(10进制),输出nn的点阵。

Computer graphics, image processing, and GIS (geographic information systems) all make use of a data
structure called a quadtree. Quadtrees represent regional or block data efficiently and support efficient
algorithms for operations like the union and intersection of images.
A quadtree for a black and white image is constructed by successively dividing the image into four
equal quadrants. If all the pixels in a quadrant are the same color (all black or all white) the division
process for that quadrant stops. Quadrants that contain both black and white pixels are subdivided
into four equal quadrants and this process continues until each subquadrant consists of either all black
or all white pixels. It is entirely possible that some subquadrants consist of a single pixel.
For example, using 0 for white and 1 for black, the region on the left below is represented by the
matrix of zeros and ones in the middle. The matrix is divided into subquadrants as shown on the right
where gray squares represent subquadrants that consist entirely of black pixels.
在这里插入图片描述
A quadtree is constructed from the block structure of an image. The root of the tree represents the
entire array of pixels. Each non-leaf node of a quadtree has four children, corresponding to the four
subquadrants of the region represented by the node. Leaf nodes represent regions that consist of pixels
of the same color and thus are not subdivided. For example, the image shown above, with the block
structure on the right, is represented by the quadtree below.
在这里插入图片描述
Leaf nodes are white if they correspond to a block of all white pixels, and black if they correspond
to a block of all black pixels. In the tree, each leaf node is numbered corresponding to the block it
represents in the diagram above. The branches of a non-leaf node are ordered from left-to-right as
shown for the northwest, northeast, southwest, and southeast quadrants (or upper-left, upper-right,
lower-left, lower-right).
A tree can be represented by a sequence of numbers representing the root-to-leaf paths of black
nodes. Each path is a base five number constructed by labeling branches with 1, 2, 3, or 4 with NW =
1, NE = 2, SW = 3, SE = 4, and with the least significant digit of the base five number corresponding
to the branch from the root. For example, the node labeled 4 has path NE, SW which is 325 (base 5)
or 1710 (base 10); the node labeled 12 has path SW, SE or 435 = 2310 ; and the node labeled 15 has
path SE, SW, NW or 1345 = 4410 . The entire tree is represented by the sequence of numbers (in base
10)
9 14 17 22 23 44 63 69 88 94 113
Write a program that converts images into root-to-leaf paths and converts root-to-leaf paths into
images.
Input
The input contains one or more images. Each image is square, and the data for an image starts with
an integer n, where |n| is the length of a side of the square (always a power of two, with |n| < 64)
followed by a representation of the image. A representation is either a sequence of n
2
zeros and ones
comprised of |n| lines of |n| digits per line, or the sequence of numbers that represent the root-to-leaf
paths of each black node in the quadtree that represents the image.
If n is positive, the zero/one representation follows; if n is negative, the sequence of black node
path numbers (in base 10) follows. The sequence is terminated by the number -1. A one-node tree
that represents an all-black image is represented by the number 0. A one-node tree that represents an
all-white image is represented by an empty sequence (no numbers).
The end of data is signaled by a value of 0 for n.
Output
For each image in the input, first output the number of the image, as shown in the sample output.
Then output the alternate form of the image.
If the image is represented by zeros and ones, the output consists of root-to-leaf paths of all black
nodes in the quadtree that represents the image. The values should be base 10 representations of the
base 5 path numbers, and the values should be printed in sorted order. If there are more than 12 black
nodes, print a newline after every 12 nodes. The total number of black nodes should be printed after
the path numbers.
If the image is represented by the root-to-leaf paths of black nodes, the output consists of an ASCII
representation of the image with the character ‘.’ used for white/zero and the character ‘’ used for
black/one. There should be n characters per line for an n × n image.
Sample Input
8
00000000
00000000
00001111
00001111
00011111
00111111
00111100
00111000
-8
9 14 17 22 23 44 63 69 88 94 113 -1
2
00
00
-4
0 -1
0
Sample Output
Image 1
9 14 17 22 23 44 63 69 88 94 113
Total number of black nodes = 11
Image 2


***
…****
…*****
…******
…*

Image 3
Total number of black nodes = 0
Image 4





#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#define Maxn 72
using namespace std;
int a[Maxn][Maxn],n;
vector <int> Ans;

inline int Change(int x,int type) {
    int ret = 0;
    if(type == 1) {
        while(x) {
            ret = ret * 5 + x % 10;
            x /= 10;
        }
        return  ret;
    }
    else {
        while(x) {
            ret = ret * 10 + x % 5;
            x /= 5;
        }
        x = 0;
        while(ret) {// 翻转
            x = x * 10 + ret % 10;
            ret /= 10;
        }
        return x;
    }
}

void output() {
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++)
            if(a[i][j]) printf("%c",'*');
            else printf("%c",'.');
        printf("\n");
    }
}

void DFS(int x,int y,int k,int t,int type){
    if(type == 1) {
        int sum = 0;
        for(int i=x; i<x+k; i++)
            for(int j=y; j<y+k; j++)
                sum += a[i][j];
        if(sum == 0) return ;
        if(sum == k * k) { Ans.push_back(Change(t,1)); return ; }
        DFS(x,y,k >> 1 ,t * 10 + 1 ,type);
        DFS(x,y + (k >> 1),k >> 1 ,t * 10 + 2 ,type);
        DFS(x + (k >> 1),y,k >> 1 ,t * 10 + 3 ,type);
        DFS(x + (k >> 1),y + (k >> 1),k >> 1 ,t * 10 + 4 ,type);
    } else {
        if(t == 0) {
            for(int i=x; i<x+k; i++)
                for(int j=y; j<y+k; j++)
                    a[i][j] = 1;
            return ;
        }
        int m = t % 10;
        if(m == 1) DFS(x ,y, k >> 1,t / 10 ,type);
        if(m == 2) DFS(x ,y + (k >> 1), k >> 1,t / 10 ,type);
        if(m == 3) DFS(x + (k >> 1), y, k >> 1,t / 10 ,type);
        if(m == 4) DFS(x + (k >> 1),y + (k >> 1), k >> 1,t / 10 ,type);
    }
}
int main(int argc,char *argv[]) {
    //freopen("out.txt","w",stdout);
    int kase = 0,temp;
    while(scanf("%d",&n) == 1 && n) {
        if(n == 0) break;
        if(kase) printf("\n");
        Ans.clear();
        printf("Image %d\n",++kase);
        if(n < 0) {
            n *= -1;
            memset(a,0,sizeof(a));
            while(scanf("%d",&temp) == 1 && temp != -1)
                DFS(1,1,n,Change(temp,0),0);
            output();
        }
        else {
            for(int i=1; i<=n; i++) {
                getchar();
                for(int j=1; j<=n; j++) a[i][j] = getchar() - '0';
            }
            DFS(1,1,n,0,1);
            sort(Ans.begin(),Ans.end());
            int k = Ans.size();
            if(k) {
                for(int i=0; i<k; i++)
                    printf("%d%c",Ans[i],( i % 12 == 11 || i == k-1 ) ? '\n' : ' ');
            }
            printf("Total number of black nodes = %d\n",k);
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
explicit spectral-to-spatial convolution for pansharpening是一种用于全色融合的显式光谱到空间卷积方法。全色融合是将高分辨率的全色(黑白)图像与低分辨率的多光谱(彩色)图像融合,以提高图像质量和细节。传统的融合方法常常使用高通滤波器进行频域操作,而explicit spectral-to-spatial convolution for pansharpening则使用基于卷积的空间域方法。 该方法基于以下原理:在全色图像中,光谱分辨率高,但空间分辨率较低;而在多光谱图像中,光谱分辨率较低,但空间分辨率较高。因此,通过将全色图像的光谱信息传递给多光谱图像,可以提高多光谱图像的空间分辨率。 explicit spectral-to-spatial convolution for pansharpening方法通过使用卷积核,将全色图像的光谱信息转换为空间域的高频细节。这个卷积核是根据光谱和空间信息之间的关系而设计的。通过将这个卷积核应用于低分辨率的多光谱图像,可以增强其空间细节,使其接近高分辨率的全色图像。 这种方法的优势在于显式地将光谱信息转换为空间域的细节,能够更好地保留图像的光谱特征和空间细节。与传统的频域方法相比,显式光谱到空间卷积方法更容易实现,并且能够更好地适应各种图像场景。 总之,explicit spectral-to-spatial convolution for pansharpening是一种通过卷积将全色图像的光谱信息转换为多光谱图像的空间细节的方法,以实现全色融合,提高图像质量和细节。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值