How to merge a contour plot with the image it is derived from

8 views (last 30 days)
Hello, I have this challenge of overlaying a contour plot with that of the image from which it was derived, as both images now have different scale axes. The program I used is attached along with the relevant mat file, jpg file from which the mat file was obtained and the resultant merged image I obtained. Please help. Thank you.
Z = load('Ir_6707.mat');
flds = fieldnames(Z);% Fieldnames of data.
field = flds{1};% First field in data structure.
A = Z.(field);
B = -272.+A;% converts from kelvin to celsius
H = fspecial('average');% Creates predefined average 2_D filter
image = imfilter(B,H);% Applies filter to image
contour(flipud(image));
[C,h] = contour(interp2(flipud(image),'spline'));
clabel(C,h);
hold on
imagesc(flipud(B));

Answers (1)

Thorsten
Thorsten on 20 Oct 2015
Edited: Thorsten on 20 Oct 2015
I failed to run your code, because
>> contour(flipud(image));
Error using flipud (line 19)
X must be a 2-D matrix.
I use Matlab R2012a.
Note that you treat A as if is where a matrix of temperature values in Kelvin; but is seems to be an RGB image. Also the correct formula is celsius = kelvin - 273.15.
To show an overlay of the image and the contour:
Z = load('Ir_6707.mat');
flds = fieldnames(Z);% Fieldnames of data.
field = flds{1};% First field in data structure.
A = Z.(field);
G = rgb2gray(A);
H = fspecial('average');%
image = imfilter(G,H);
imshow(A)
contour(image)
  2 Comments
Ogheneochuko
Ogheneochuko on 20 Oct 2015
Thanks. But I am using Matlab R2015a and when I run the program it generates the error below;
Error using rgb2gray>parse_inputs (line 82)
MAP must be a m x 3 array.
Error in rgb2gray (line 37)
X = parse_inputs(X);
As such the code is not executed to completion.
Thorsten
Thorsten on 21 Oct 2015
Edited: Thorsten on 21 Oct 2015
That's strange. After the first four lines, I get
>> whos A
Name Size Bytes Class Attributes
A 240x320x3 230400 uint8
which is definitely a valid argument for rgb2gray. Are you using a different A or mat-file?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!