绘制从一个图像到另一个图像获得的轮廓

时间:2016-02-12 06:09:10

标签: python matlab

如何绘制从一幅图像到另一幅图像的轮廓图?

我的original图片和changes图片大小相同,但changes只有部分original。我希望这些部分在original

上以彩色突出显示

我有相同的python代码:

original   = cv2.imread(image1_path)     #this should be background
changes    = cv2.imread(image2_path)     #contours found from this should come over original    
ret,thresh = cv2.threshold(changes,127,255,0)    
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,
                                              cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContours(original, contours, -1,(0,0,255), 2)

如何在Matlab中做同样的事情?

修改

changes  = imread('changes.jpg');
original = imread('original.jpg')
c        = edge(changes,'canny');
original(:,:,1) = original;                           
original(:,:,2) = original(:,:,1);                    
original(:,:,3) = original(:,:,1);
imshow(original+repmat(uint8(c),[1,1,3])*255);

1 个答案:

答案 0 :(得分:1)

要在原始图像上以红色绘制轮廓并将输出保存到文件,请按以下步骤操作:

im=imread('braincube.png');
c=edge(rgb2gray(im),'canny');
% c=imdilate(c, strel('disk', 2)); % optional increase thickness
c2=bsxfun(@times, repmat(c, [1,1,3]), reshape([255,-255,-255],[1,1,3]));
imwrite(uint8(double(im)+c2), 'output.png');