[R,C,D] = size(im1); im2 = cat(3,imresize(im2(:,:,1),[R,C]),... imresize(im2(:,:,2),[R,C]),... imresize(im2(:,:,3),[R,C])); function [coorList,num] = SpotTheDifferences(im1,im2) % 平滑 H = fspecial('gaussian',7,3); smooth1 = imfilter(im1,H,'same'); smooth2 = imfilter(im2,H,'same'); % 差 ecolor = uint8(abs(double(smooth1)-double(smooth2))); egray = rgb2gray(ecolor); % 二值 bw = imbinarize(egray); % 去小噪 se = strel('disk',5); obj1 = imopen(bw,se); % 合大体 se = strel('disk',11); obj2 = imclose(obj1,se); % 目标 [label,num] = bwlabel(obj2); coorList = zeros(num,4); for n = 1:num [y,x] = find(label==n); y1 = min(y); y2 = max(y); x1 = min(x); x2 = max(x); coorList(n,:) = [x1,x2,y1,y2]; %% {找不同} [coorList,num] = SpotTheDifferences(im1,im2); %% {绘制} subplot(121),imshow(im1) hold on for n = 1:num drawbox(coorList(n,:)) end subplot(122),imshow(im2) hold on for n = 1:num drawbox(coorList(n,:)) end % ----function---- function drawbox(coor) x1 = coor(1); x2 = coor(2); y1 = coor(3); y2 = coor(4); x = [x1,x1,x2,x2,x1]; y = [y1,y2,y2,y1,y1]; plot(x,y,'r-','LineWidth',2) end
时间: 2024-01-29 11:02:55 浏览: 70
im2mov.rar_im2mov_图片合成视频
这段代码的作用是找出两张图片的不同之处,并在两张图片上绘制出这些不同之处的框。具体实现过程是先将两张图片进行平滑处理,然后计算它们的差异,再将差异图像转化为二值图像,去除小噪声,合并大体,最后找出目标区域并绘制框。其中,SpotTheDifferences函数用来找出不同之处的坐标列表和数量,drawbox函数用来绘制矩形框。
阅读全文