在Matlab中对实验结果进行局部放大

在Matlab中对实验结果进行局部放大

在图像去噪研究中,通常使用SNR, PSNR, MSE, and SSIM等标准去定量衡量去噪的效果,然而,这是需要原图作为benchmark的,在实际获取的图像中,不可能得到原图,这时对去噪效果的衡量往往需要视觉对比。
代码及结果展示:

clc;
clear;
[f,p]=uigetfile('*.*','选择图像文件','C:\Users\...\jpg');
if f
A=imread(strcat(p,f));
im_src=double(A);
end
% 交互式选择pending image
[height, width, channel1] = size(im_src);

% define the start position, the rect size, the magnification factor
% [start_y, start_x] = deal(230, 140);
rect_size = 50;
m_factor = 2.2; 

% acquire magnificated rect
tt = im_src(start_y:start_y+rect_size-1, start_x:start_x+rect_size-1, :);
tt_big = imresize(tt,m_factor);
[m_height, m_width, channel2]=size(tt_big);

% achieve magnificated in the lower right corner of image
if channel1 == 3
    for i=1:3
        %% 右下角
%         im_src(height-m_height+1:height, width-m_width+1:width, i)=tt_big(:,:,i);
        %% 左上角
%          im_src(1:m_height, 1:m_width, i)=tt_big(:,:,i);  
        %% 右上角
%         im_src(1:m_height, width-m_width+1:width, i)=tt_big(:,:,i);
        %% 左下角
        im_src(height-m_height+1:height, 1:m_width, i)=tt_big(:,:,i);
        
    end
else
    im_src(height-m_height+1:height, width-m_width+1:width)=tt_big;
end

% draw two rects in the image 给图片描框
s=draw_rect(im_src, [start_y,start_x],[rect_size, rect_size], 2, [0, 255, 0]);% [R,G,B]

%% 右下角
% result=draw_rect(s, [height-m_height, width-m_width],[m_height, m_width], 3, [255, 0, 0]);
%% 左上角
% result=draw_rect(s, [1, 1],[m_height, m_width], 3, [255, 0, 0]);
%% 右上角
% result=draw_rect(s, [1, width-m_width+1],[m_height, m_width], 3, [255, 0, 0]);
%% 左下角
result=draw_rect(s, [height-m_height+1, 1],[m_height, m_width], 3, [255, 0, 0]);

imshow(uint8(result));
imwrite(uint8(result), 'test20.png');

draw_rect函数:

function [ dest ] = draw_rect( src, startPosition, rectSize,  lineSize, color )

[start_y, start_x] = deal(startPosition(1),startPosition(2));
[rect_size_w, rect_size_h] = deal(rectSize(1),rectSize(2));

[~, ~, channel] = size(src);
if channel==1
    dest(:, : ,1) = src;
    dest(:, : ,2) = src;
    dest(:, : ,3) = src;
else
    dest = src;
end

for channel_i = 1 : 3              
    for line_i = 1 : lineSize		% expand inside
	gain = line_i-1;
         dest( start_y+gain, (start_x+gain):(start_x+rect_size_w-gain),       channel_i ) =  color(channel_i);	%above
         dest( start_y+rect_size_h-gain,  (start_x+gain):(start_x+rect_size_w-gain),       channel_i ) =  color(channel_i);	%bottom
         dest( (start_y+gain) : (start_y+rect_size_h-gain),     start_x+gain,              channel_i ) =  color(channel_i);	%left
         dest( (start_y+gain) : (start_y+rect_size_h-gain),     start_x+rect_size_w-gain,  channel_i ) =  color(channel_i);	%right
    end    
end 

在这里插入图片描述

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值