Ale*_*exx 8 c++ algorithm photo image-processing visual-c++
Hy.我要做的是创建一个程序(使用C或C++),它将24位/像素位图作为输入并收集图像,我必须创建一个马赛克图像,类似于使用该库的输入图像给出的图像(创建马赛克照片类似于输入).
到目前为止,我可以访问输入的图像像素和颜色,但我有点卡住了.我的问题是我应该从哪里开始?我需要一个可以做这种事情的基本算法.我真的找不到任何东西(也许我看错了).还有人可以告诉我一个随机照片下载器,以便我可以下载项目的小图像?有人能帮我吗?请告诉我从哪里开始和使用什么.
I82*_*uch 16
我在Scala中做过这个.该布斯博士的文章对我来说是非常有用的.
示例图片:

这是我的基本算法:
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
}
Run Code Online (Sandbox Code Playgroud)
我的完整源代码可以在github上找到