matlab图像处理基础知识1(双线性插值matlab实现--等比例调整缩放倍数)
2016-05-25 17:07
946 查看
需求说明:FPGA图像处理前期算法验证
当前状态:已通过matlab验证
%当前算法只能等比例放大或者缩小
function scaler_bilinear_matlab()
%-----------------------------0:配置输入输出--------------------------------
I=imread('F:\book\Digital image processing and machine vision\640480\plane.jpg');%读入原图像
[width_sr,height_sr,l]=size(I); %读取图像矩阵大小,方便后面操作
K = str2double(inputdlg('please input scale factor (must between 0.2 - 5.0)', 'INPUT scale factor', 1, {'0.5'}));
width = K * width_sr;
height = K * height_sr;
O = uint8(zeros(width,height,l));
widthScale = width_sr/width; %横向放大系数
heightScale = height_sr/height; %纵向放大系数
%-----------------------------1:开始输出计算--------------------------------
for x = 5:width - 5 % 5是为了防止矩阵超出边界溢出
for y = 5:height - 5
xx = x * widthScale; % xx, yy为原坐标,x,y为新坐标
yy = y * heightScale;
%-----------------------------2:边界处理-----------------------------------
if (xx/double(uint16(xx)) == 1.0) & (yy/double(uint16(yy)) == 1.0)
O(x,y,:) = I(int16(xx),int16(yy),:); % 若xx,yy为整数,直接赋值
else
%-----------------------------3:原坐标四个相邻点----------------------------
a = double(uint16(xx)); % xx, yy为原坐标,x,y为新坐标
b = double(uint16(yy)); % xx, yy为原坐标,x,y为新坐标
x11 = double(I(a, b, :)); % x11 <- I(a,b)
x12 = double(I(a, b+1,:)); % x12 <- I(a,b+1)
x21 = double(I(a+1,b, :)); % x21 <- I(a+1,b)
x22 = double(I(a+1,b+1,:)); % x22 <- I(a+1,b+1)
%-----------------------------4:计算输出图像数值----------------------------
O(x,y,:) = uint8( (b+1-yy) * ( (xx-a)*x21 + (a+1-xx)*x11 ) + (yy-b) * ( (xx-a)*x22 + (a+1-xx) * x12) );% 用双线性插值计算公式计算
end
end
end
%-----------------------------6:输出显示------------------------------------
figure,imshow(I); title('输入图像640*480');
figure,imshow(uint8(O));title('输出图像1920*1080');
设计来自:时间的诗
当前状态:已通过matlab验证
%当前算法只能等比例放大或者缩小
function scaler_bilinear_matlab()
%-----------------------------0:配置输入输出--------------------------------
I=imread('F:\book\Digital image processing and machine vision\640480\plane.jpg');%读入原图像
[width_sr,height_sr,l]=size(I); %读取图像矩阵大小,方便后面操作
K = str2double(inputdlg('please input scale factor (must between 0.2 - 5.0)', 'INPUT scale factor', 1, {'0.5'}));
width = K * width_sr;
height = K * height_sr;
O = uint8(zeros(width,height,l));
widthScale = width_sr/width; %横向放大系数
heightScale = height_sr/height; %纵向放大系数
%-----------------------------1:开始输出计算--------------------------------
for x = 5:width - 5 % 5是为了防止矩阵超出边界溢出
for y = 5:height - 5
xx = x * widthScale; % xx, yy为原坐标,x,y为新坐标
yy = y * heightScale;
%-----------------------------2:边界处理-----------------------------------
if (xx/double(uint16(xx)) == 1.0) & (yy/double(uint16(yy)) == 1.0)
O(x,y,:) = I(int16(xx),int16(yy),:); % 若xx,yy为整数,直接赋值
else
%-----------------------------3:原坐标四个相邻点----------------------------
a = double(uint16(xx)); % xx, yy为原坐标,x,y为新坐标
b = double(uint16(yy)); % xx, yy为原坐标,x,y为新坐标
x11 = double(I(a, b, :)); % x11 <- I(a,b)
x12 = double(I(a, b+1,:)); % x12 <- I(a,b+1)
x21 = double(I(a+1,b, :)); % x21 <- I(a+1,b)
x22 = double(I(a+1,b+1,:)); % x22 <- I(a+1,b+1)
%-----------------------------4:计算输出图像数值----------------------------
O(x,y,:) = uint8( (b+1-yy) * ( (xx-a)*x21 + (a+1-xx)*x11 ) + (yy-b) * ( (xx-a)*x22 + (a+1-xx) * x12) );% 用双线性插值计算公式计算
end
end
end
%-----------------------------6:输出显示------------------------------------
figure,imshow(I); title('输入图像640*480');
figure,imshow(uint8(O));title('输出图像1920*1080');
设计来自:时间的诗
相关文章推荐
- matlab图像处理基础知识0(双线性插值matlab实现--调整水平和垂直放大倍数)
- matlab处理多个文件夹中的image,保存为mat格式。
- matlab限制范围
- 深度学习 Deep Learning with MATLAB(懒人版)
- MATLAB _GUI初识
- 学习笔记-MATLAB的sort
- Piotr's Computer Vision Matlab Toolbox 安装
- MATLAB FDATool IIR数字滤波器设计
- MATLAB与VC混编中的DLL加载问题
- PID自学笔记-入门级
- matlab2013a(x64) 安装 libsvm
- MATLAB开山篇
- 从plotyy谈一张图双坐标系的画法
- Matlab同一张图中多种颜色的表示方法
- Matlab_001:clc与clear
- matlab求凸包
- Matlab 画图字体,字号的设定,图片大小和比例
- matlab 批量处理图片
- matlab图像处理
- hog特征原理详解及matlab代码学习笔记