how to overlay(superimpose) contour plot(coloured) over a gray scale image

I am trying to superimpose a colored contour plot on a grayscale image. I used hold on and then i tried to plot a contour plot. Also i tried using two color maps in a same figure window. But even that is not working. Pls do help me in solving this problem. Typically the contour plot occupies only the central part of the greyscale image , the rest is the greyscale image.

 Risposta accettata

A grayscale image with a colored contour plot superimposed:
% Make some sample grayscale image
I = abs(sin((1:500)'/100)*sin((1:500)/100));
% Convert the grayscale image to RGB
Irgb = cat(3,I,I,I);
% Plot the image and some contours in color
image(Irgb)
hold all
contour(I);
0000 Screenshot.png

4 Commenti

Actually i want to have contourf plot over a grayscale image. I tried your idea, but the contourf plot over the grayscale image is fully blue even though only contourf plot is giving the right plot will lot of colors. An excerpt of the code is given below
" figure;
I=uint8(ref_image);
% Convert the grayscale image to RGB
Irgb = cat(3,I,I,I);
image(Irgb)
hold all
contourf(z1,z2, displacement_x);
colormap('default');
xlim([1, 1392]); ylim([1, 1040]);
xlabel('x (pixels)', 'FontName', 'Arial', 'FontSize', 14); ylabel('y (pixels)', 'FontName', 'Arial', 'FontSize', 14);
set(gca,'XAxisLocation', 'top', 'YDir', 'reverse', 'FontName', 'Palatino Linotype', 'FontSize', 13, 'DataAspectRatio', [10000 10000 1]);
colorbar
"
Can you help me out
You need to scale the "clim" property of the axes to fit the data from CONTOURF.
Put this line at the end:
set(gca,'clim',[min(displacement_x(:)) max(displacement_x(:))]);
This will all cover up your grayscale image though.
Do you want to make the contour plot transparent? Because that might be not be very simple if you use CONTOURF...
Thanks a lot...I do not want the contour plot to be transparent..By setting up clim, its working as i wanted...

Accedi per commentare.

Più risposte (3)

You haven't indicated what problem you are encountering. Your reference to two color maps hints that you are having getting the two to come out with the colors you want.
Contour plots are a hggroup object that has children that are patch objects. You can change the color properties of the patch objects. The only real trick that have found is that in order to switch between filled and non-filled, you have to change a property in the hggroup object that is the parent of the patch objects.
salut ,
j'ai une image a et une image b qui est un contour de a et je veux superposer le contour sur l'image d'origine a.
Quoi faire ?

1 Commento

Not sure what you're asking, but did you see Teja's answer above?
Or do you mean like where you want to stack the RGB images vertically, like this:
% Takes an RGB image and stacks the separate color channels at different Z levels.
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
rgbImage = imread('peppers.png');
% Extract the individual red, green, and blue color channels.
redChannel = im2double(rgbImage(:, :, 1));
greenChannel = im2double(rgbImage(:, :, 2));
blueChannel = im2double(rgbImage(:, :, 3));
H(1) = slice(repmat(redChannel,[1 1 2]),[],[], 1); %slice() requires at least 2x2x2
set(H(1),'EdgeColor','none') %required so image isn't just an edge
hold on
H(2) = slice(repmat(greenChannel,[1 1 2]),[],[], 2); %slice() requires at least 2x2x2
set(H(2),'EdgeColor','none') %required so image isn't just an edge
H(3) = slice(repmat(blueChannel,[1 1 3]),[],[], 3); %slice() requires at least 2x2x2
set(H(3),'EdgeColor','none') %required so image isn't just an edge
hold off
colormap(gray(256))
axis ij
0000 Screenshot.png

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by