Code covered by the BSD License  

Highlights from
Contour Plot onto Image

from Contour Plot onto Image by Prakash Manandhar
Plots contour points onto Image

PlotContour (im, c, rMin, rMax, M, N, contour_color)
function imC = PlotContour (im, c, rMin, rMax, M, N, contour_color)
% PLOTCONTOUR Plots given contour to the given image. rMin, rMax, M and N
% are as defined in IMTOPOLAR. contour_color is the [r g b] value of the
% color used for the contour.
%
% c is a contour consisting of N indices (from 1 to M) for each N theta. It
% is a N element vector.
%
% V0.1 Created 8 Dec, 2007 Prakash Manandhar (pmanandhar@umassd.edu)


[Mr Nr Cr] = size(im);

delR = (rMax - rMin)/(M-1);
imC = zeros(Mr, Nr, 3);

if Cr == 1 % if grayscale convert to color
    imC(:,:,1) = im; imC(:,:,2) = im; imC(:,:,3) = im;
else
    imC = im;
end

Om = (Mr+1)/2; % co-ordinates of the center of the image
On = (Nr+1)/2;
sx = (Mr-1)/2; % scale factors
sy = (Nr-1)/2;

for ti = 1:N
    t = 2*pi*(ti-1)/(N-1);
    r = rMin + delR*c(ti);
    x = r*cos(t);
    y = r*sin(t);
    xR = round(x*sx + Om);  
    yR = round(y*sy + On);
    if xR < 1 
        xR = 1;
    elseif xR > Mr
        xR = Mr;
    end
    if yR < 1
        yR = 1;
    elseif yR > Nr
        yR = Nr;
    end
    imC(xR, yR, :) = contour_color;
end

Contact us