700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【数字图像处理】浮雕效果和倒影效果

【数字图像处理】浮雕效果和倒影效果

时间:2019-02-03 02:05:20

相关推荐

【数字图像处理】浮雕效果和倒影效果

Ø【作业要求】

Perform either of the following two tasks:

1. Write your own imresize() function codeto simulate the matab function imresize(). You should implement at least the‘nearest’ and the ‘bilinear’ methods. Compare you result with the matlabfunction imresize().

2.Design interpolation or tranformation algorithm to build some cool images.

Submit your code, result, and report. Youcan use the two attached images or other images for testing.

Ø【作业思路】

一、浮雕效果

每个像素的RGB值都设置为该位置的初始值img(I,j)减去其右下方第二的像素img(i+5,j+5)的差,最后统一加上128用于控制灰度,显示出类似浮雕的灰色。

这样处理的思路是,将图像上的每个点与它的对角线的像素点形成差值,这样淡化相似的颜色,突出不同的颜色、边缘,从而使图像产生纵深感,产生类似于浮雕的效果。

开始我采用了img(I,j)-img(i+1,j+1),后来与img(I,j)-img(i+5,j+5)实现的效果比较后发现,后者变换后的图像更“凸出”,效果更好,于是就采用了后者。

效果如下:

二、水中倒影效果

倒影效果分两部分实现:

第一部分是对原图像的模糊化,用来展现水中倒影的样子。

这里的模糊是采用让每个像素点在原来的位置周围随机振荡的方式实现的。具体来看,我是生成了两个随机变量deltax,deltay作为像素”跳跃”的坐标变化——即将img(i+deltax,j+deltay)处的值复制到img(I,j)处。这个像素”跳跃“的范围在半径为20的圆内。

第二部分是图像的拼接。首先需要将第一部分中获得的模糊图像镜面反转。

然后生成一个原图像两倍大的图像——宽度不变,高度变为原来的两倍。其中,新图像的上半部分为原图像,下半部分为镜面反射后的模糊图像。拼在一起后,就形成了水中倒影的效果。

上期谜语:不施粉黛(二字数字图像术语)—— 像素

Ø【文件说明】

main.m:

主程序,包含了对图像进行浮雕效果和倒影效果的处理程序。

%% relievo the imageimg1 = imread('ha.jpg');ret1 = relievo(img1);subplot(1,2,1);imshow(img1);subplot(1,2,2);imshow(ret1);%% dim the image & create the inverted reflection in waterimg2 = imread('building.jpg');% dim the imageret2 = dim(img2); % direct reflection of the dim imageret2 = flip(ret2);m = size(ret2, 1);n = size(ret2, 2);% combine the source image & the dim imagefor i = 1:mfor j = 1:nfor k = 1:3output(i,j,k) = img2(i,j,k);endendend% combine the source image & the dim imagefor i = 1:mfor j = 1:nfor k = 1:3output(i+m,j,k) = ret2(i,j,k);endendendsubplot(1,2,1);imshow(img2);subplot(1,2,2);imshow(output);

relievo.m:

对传进来的图像矩阵进行浮雕效果变换的函数。

function [ ret ] = relievo( img )%RELIEVO transform the pictures to relievo styleR = img(:,:,1); G = img(:,:,2); B = img(:,:,3); m = size(img, 1);n = size(img, 2);for i = 1:m-5for j = 1:n-5RR(i,j) = R(i,j) - R(i+5,j+5) + 128;GG(i,j) = G(i,j) - G(i+5,j+5) + 128;BB(i,j) = B(i,j) - B(i+5,j+5) + 128;endendret(:,:,1) = RR;ret(:,:,2) = GG;ret(:,:,3) = BB;end

dim.m:

对传进来的图像矩阵进行模糊的函数,作为倒影。

function [ ret ] = dim( img )%DIM transform the pictures to be dimedR = img(:,:,1); G = img(:,:,2); B = img(:,:,3); m = size(img, 1);n = size(img, 2);for i = 1:m-20for j = 1:n-20deltax = fix(rand(1)*20);deltay = fix(rand(1)*20);ii = i + deltax;jj = j + deltay;RR(i,j) = R(ii,jj);GG(i,j) = G(ii,jj);BB(i,j) = B(ii,jj);endendret(:,:,1) = RR;ret(:,:,2) = GG;ret(:,:,3) = BB;end

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。