照片拼接算法。如何创建一个马赛克的照片给定的基本形象和瓷砖的名单? [英] Photo Mosaic Algorithm. How to create a mosaic photo given the basic image and a list of tiles?

查看:134
本文介绍了照片拼接算法。如何创建一个马赛克的照片给定的基本形象和瓷砖的名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy.What我要做的是创建一个程序(用C或C ++),即需要输入一个24位/像素的位图和图像的聚会,我必须创建一个马赛克图像,类似于输入图像使用给定的图像的库(要创建镶嵌照片类似于输入)。

Hy.What I have to do is to create a program (using C or C++), that takes as input a 24bits/pixel bitmap and a gathering of images and I have to create a mosaic image , similar to the input image using the library of images given(To create a mosaic Photo similar to the input).

到目前为止,我可以访问该输入的图像像素,并从它的颜色,但我有点卡住。我的问题是我应该从哪里开始呢?我需要一个基本的算法,可以做这样的事情。我真的不能找到任何(也许我在找错了)。并且还可以有人告诉我一个随机的照片下载器,这样我可以下载小图片的项目?有人可以帮我吗?请告诉我从哪里开始以及要使用的。

So far I can access the input's image pixels and the colors from it but I'm kind of stuck. My question is Where should I start? I need a basic algorithm that could do such a thing. And I can't really find any(maybe I'm looking wrong). And also can someone tell me a random photo downloader, so that i can download small images for the project? Can someone help me? Please, tell me where to start and what to use.

推荐答案

我在Scala中做到了这一点。该 Dr Dobbs的文章是非常有用的我。

I've done this in Scala. The Dr Dobbs article was extremely useful to me.

样图:

这是我的基本算法:

def createMosaic(targetImage:BufferedImage,
  index:PhotoIndexer.PhotoIndex,
  opacity:Float,
  targetWidth:Int,
  targetHeight:Int,
  numRows:Int,
  numColumns:Int, callback:PhotoMosaicCallback): ImageGrid = {

      var indexCopy = index

      // Map from the buffered image to that image's average color
      var colorMap:Map[BufferedImage,Color] =
      index.values.map(data => (data.thumbnail, data.avgColor)).toMap

      // We look at rectangular regions of the target image, calculate their average
      // colors, and then pick images that match those colors.
      val sampleWidth = targetImage.getWidth / numColumns
      val sampleHeight = targetImage.getHeight / numRows

      // Used to report the progress of the process
      var counter = 1
      val numSubImages = numRows * numColumns

      val imageGrid:ImageGrid = Array.fill(numRows, numColumns)(Nil)

      // for each patch in the image
      for (row <- 0 until numRows) {
        for (column <- 0 until numColumns) {
          val x = column * sampleWidth
          val y = row * sampleHeight
          // This is the small rectangular region of the target image that we're
          // currently considering
          val subImage = targetImage.getData(new Rectangle(x,y,sampleWidth,sampleHeight))
          val avgImageColor = calculateColorFromRaster(subImage)

          val nearest:Seq[BufferedImage] = getNearestColorImages(avgImageColor, colorMap)

          // nearest is in sorted order; pick one of them and draw it to correct place in
          // image
          imageGrid(row)(column) = nearest

          callback.photosCalculated(row, column, nearest)

          val percent = 100.0 * counter / numSubImages
          // TODO: for GUI version, use a display bar
          if (counter % 100 == 0) {
            println(percent + " completed (" + counter + " of" + numSubImages + ")")
          }
          counter+=1
        }
      }
      imageGrid

}

我的全部源$ C ​​$ c是在github可

这篇关于照片拼接算法。如何创建一个马赛克的照片给定的基本形象和瓷砖的名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆