版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
斯坦福大学李飞飞团队的风格迁移模型是一种基于深度学习的图像处理技术,可以将一张图像的风格转移到另一张图像上。该模型最初由Gatys等人提出,后来被李飞飞团队进一步优化和改进。该模型在图像处理领域具有广泛的应用,例如艺术风格转换、视频风格迁移等。
原图
10种模型可以在这里下载:
深度神经网络下的风格迁移模型资源-CSDN文库
处理代码:http://blog.csdn.net/uruseibest
'风格序号Dim styleindex As Integer = 0'风格迁移Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click'需要测试的图像文件Dim m As New Mat("C:\learnEmgucv\tower.jpg", ImreadModes.Color)Dim hm As Single = m.HeightDim wm As Single = m.Width'10种风格迁移Dim styles(9) As Stringstyles(0) = "C:\learnEmgucv\styletransfer\eccv16\starry_night.t7"styles(1) = "C:\learnEmgucv\styletransfer\eccv16\composition_vii.t7"styles(2) = "C:\learnEmgucv\styletransfer\eccv16\la_muse.t7"styles(3) = "C:\learnEmgucv\styletransfer\eccv16\the_wave.t7"styles(4) = "C:\learnEmgucv\styletransfer\instance_norm\candy.t7"styles(5) = "C:\learnEmgucv\styletransfer\instance_norm\feathers.t7"styles(6) = "C:\learnEmgucv\styletransfer\instance_norm\la_muse.t7"styles(7) = "C:\learnEmgucv\styletransfer\instance_norm\mosaic.t7"styles(8) = "C:\learnEmgucv\styletransfer\instance_norm\the_scream.t7"styles(9) = "C:\learnEmgucv\styletransfer\instance_norm\udnie.t7"'https://blog.csdn.net/uruseibestDim net As Dnn.Netnet = DnnInvoke.ReadNet(styles(styleindex))Dim blob As Matblob = DnnInvoke.BlobFromImage(m, 1.0, New Drawing.Size(wm, hm), New MCvScalar(0, 0, 0), False, False)net.SetInput(blob)Dim mout As New Matmout = net.Forward()'返回一个四维数组Dim fout(,,,) As Singlefout = mout.GetData()'返回维度:'第1维:图像数量,这里是1 https://blog.csdn.net/uruseibest'第2维:通道数量 '3'第3维:高度 ''第4维:宽度 ''在实际中需要将第2维、第3维、第4维提取出来组成一个图像Dim channels As Integer = fout.GetLength(1)Dim height As Integer = fout.GetLength(2)Dim width As Integer = fout.GetLength(3)Dim vm As New VectorOfMatFor i As Integer = 0 To channels - 1'取出每个通道Dim matr As New Matrix(Of Integer)(New Size(width, height))For j As Integer = 0 To height - 1For k As Integer = 0 To width - 1matr(j, k) = CInt(fout(0, i, j, k))NextNext'将每个通道图像加入到VectorOfMat,总共3个通道vm.Push(matr.Mat)Next'https://blog.csdn.net/uruseibestDim outputmat As New Mat'合并通道CvInvoke.Merge(vm, outputmat)ImageBox1.Image = outputmatIf styleindex = 9 Then styleindex = 0 Else styleindex += 1
End Sub
处理后的图片:http://blog.csdn.net/uruseibest
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net 教程 目录