解决这个图像处理挑战的指针是什么?

5

IOI 2013年的第二个问题如下所述:

You have an Art History exam approaching, but you have been paying more attention to informatics at school than to your art classes! You will need to write a program to take the exam for you.

The exam will consist of several paintings. Each painting is an example of one of four distinctive styles, numbered 1, 2, 3 and 4. Style 1 contains neoplastic modern art. Style 2 contains impressionist landscapes. Style 3 contains expressionist action paintings. Style 4 contains colour field paintings.

Your task is, given a digital image of a painting, to determine which style the painting belongs to.

The image will be given as an H×W grid of pixels. The rows of the image are numbered 0, …, (H ­ 1) from top to bottom, and the columns are numbered 0, …, W ­ 1 from left to right. The pixels are described using two­dimensional arrays R , G and B , which give the amount of red, green and blue respectively in each pixel of the image. These amounts range from 0 (no red, green or blue) to 255 (the maximum amount of red, green or blue).

Implementation You should submit a file that implements the function style(), as follows:

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]);

This function should determine the style of the image. Parameters are:

  • H: The number of rows of pixels in the image.
  • W: The number of columns of pixels in the image.
  • R: A two­dimensional array of size H×W , giving the amount of red in each pixel of the image.
  • G: A two­dimensional array of size H×W , giving the amount of green in each pixel of the image.
  • B: A two­dimensional array of size H×W , giving the amount of blue in each pixel of the image.

示例图片在问题PDF中。

我不想要一个现成的程序。提供一两个提示让我开始会很好,因为我对这个问题毫无头绪。


2
“给我一两个提示让我开始会很好”,但这对其他参与者是不公平的。 - Daniel Daranas
8
比赛已经结束。http://www.ioi2013.org/ - Soham Chowdhury
1
在这里也可以试一下 Code Golf - Suvarna Pattayil
1
提示?但标题要求指针!http://xkcd.com/138/ - fire.eagle
@fire.eagle 我就知道这会发生。 - Soham Chowdhury
您的标题需要改进。我们已经知道您需要帮助,这也是您来到这里的原因。 - ctrl-alt-delor
2个回答

15

由于提供的图像数据是以RGB格式提供的,因此首先需要准备一份相同的图像数据,但采用YUV格式。这很重要,因为Luma(Y)和Chroma(U,V)地图中的某些图像特征易于识别。

根据提供的示例,以下是每种“风格”艺术的一些显著特点:


风格1 - 新构主义现代艺术

新构主义现代艺术

  • 零颗粒感 - 检查均匀Luma(Y)的大面积区域。
  • 黑色像素在区域边缘(不同色度之间的过渡)。

风格2 - 印象派风景画

印象派风景画

  • 高颗粒度 - 在Luma(Y)中检查熵高(类盐和胡椒噪声)的模式。
  • 以绿色为主 - 绿色通道中的高值。
    绿avg >> 红avg
    绿avg >> 蓝avg

风格3 - 表现主义行动绘画

表现主义行动绘画


Style4 - 色块画

色块画

  • 零纹理 - 检查是否有大面积均匀的亮度(Luma(Y))
  • 没有黑色(或接近黑色)像素在不同色度之间的转换位置。

只要输入图像属于上述类别之一,您就可以通过将图像数据通过实现识别上述特征的功能来进行分类而毫无问题。

基本上,它归结为以下代码流程:

  • 图像具有均匀的亮度
    • (如果是) 图像在色度转换处有黑色像素
      • (如果是) Style1
      • (如果不是) Style4
    • (如果不是) 图像较绿
      • (如果是) Style2
      • (如果不是) Style3

采样也很重要,我的意思是如何从给定的RGB区域“量化”YUV参数。这可能有些棘手。 - user2485710
@user2485710 你说得对。但是由于我们不感兴趣任何形式的压缩,因此我们不会进行色度子采样。可以使用简单的公式,如这里所示。请查看这篇短文和C++代码,演示了色度子采样引入的相对差异和视觉伪影。 - TheCodeArtist
代码流程背后的推理是有缺陷的。表现主义行动绘画也可以是绿色的。 - Daniel Daranas
1
@DanielDaranas 同意。答案仅基于问题陈述中提供的示例图像。OP明确要求提示如何在合理的时间内分类图像。通过已知“风格”的其他示例图像,逻辑可以(并且需要)进行调整。 - TheCodeArtist

0

也许你可以先尝试使用颜色和形状来进行处理... 在新艺术主义中,可能只会有少量的颜色,占据着几何区域,就像色块画一样。

这可能会让你能够区分风格1和4与风格2和3。

在风格1和4中,你会看到大面积的相同颜色,但在风格4中,颜色很少是纯色,而是由颜色的不同阴影组成的笔触。

无论如何,你应该研究每种风格的特点,了解它们通常使用的颜色和方法,然后尝试让你的函数“看到”它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接