MATLAB-How to put one image on another?

758 Views Asked by At

I have an image

enter image description here

I have obtained its phase only reconstructed image using fftn function.

My aim is

  1. Using phase only reconstruction of the given image,i will get only edges and lines

  2. Then i want to color these lines and edges say with red or blue color in the phase only reconstructed image.

  3. Then i want to put this "colored" image on original image so that edges and lines from the original images can be high-lightened with respective red or blue color.

But when i run the code, i get following error

'Subscript indices must either be real positive integers or logicals.

Error in sagar_image (line 17) superimposing(ph) = 255;'

So what should I do?

clc;
close all;
clear all;

img=imread('D:\baby2.jpg');
figure,imshow(img);
img=rgb2gray(img);

fourier_transform=fftn(img);%take fourier transform of gray scale image

phase=exp(1j*angle(fourier_transform));
phase_only=ifftn(phase);%compute phase only reconstruction
figure,imshow(phase_only,[]);

ph=im2uint8(phase_only);%convert image from double to uint8 
superimposing = img;
superimposing(ph) = 255;  
figure,
imshow(superimposing,[]), 
1

There are 1 best solutions below

2
On

superimposing(ph) = 255 could mean - 1. ph contains indices of superimposing that you wish to paint white(255). 2. ph is a 'logical' image of the same size as superimposing, every pixel that evaluates to 'true' in ph would be painted white in superimposing.

What you meant was probably:

threshold = 0.2;
superimposing(real(phase_only) > threshold) = 255;

If you want to fuse the two images and see them one on top of the other use imfuse:

imshow(imfuse(real(phase_only), img, 'blend'))