How to apply lifting wavelet transform on image fusion

2 views (last 30 days)
close all;clear;clc
%% Read Images
%% the size of images must be equal
a=imread("CT_Image2.jpg");
a=rgb2gray(a);
a=imresize(a,[276,276]);
b=imread("MRI_Image.jpg");
b=rgb2gray(b);
b=imresize(b,[276,276]);
%% Wavelet Transform
lscheme = liftingScheme('Wavelet','bior3.7');
[a1,b1,c1,d1]=lwt2(a,'LiftingScheme',lscheme,'Level',2);
%a1 is approximate coefficient matrix
%b1,c1,d1 are detail horizontal,vertical and diagonal coefficient matrix respectively
[a2,b2,c2,d2]=lwt2(b,'LiftingScheme',lscheme,'Level',2);
%a2 is approximate coefficient matrix
%b2,c2,d2 are detail horizontal,vertical and diagonal coefficient matrix respectively
[k1,k2]=size(a1);
%% Fusion Rules
a3 = zeros([k1 k2]);%preallocating with zeros
%% Average Rule
for i=1:k1
for j=1:k2
a3(i,j)=(a1(i,j)+a2(i,j))/2;
end
end
%% Max Rule
b3 = zeros([k1 k2]);%preallocating with zeros
c3 = zeros([k1 k2]);%preallocating with zeros
d3 = zeros([k1 k2]);%preallocating with zeros
for i=1:k1
for j=1:k2
b3(i,j)=max(b1(i,j),b2(i,j));
c3(i,j)=max(c1(i,j),c2(i,j));
d3(i,j)=max(d1(i,j),d2(i,j));
end
end
%% Inverse Wavelet Transform
c=ilwt2(a3,b3,c3,d3,'LiftingScheme',lscheme,'Level',2);
I have apply lifting scheme on image fusion .However, have error come out for max rule, how to fix this problem?
  1 Comment
Sharmin Kibria
Sharmin Kibria on 2 Jun 2023
The error is coming from b3(i,j)=max(b1(i,j),b2(i,j));
b1 and b2 are cell arrays. The entries b1(i,j) and b2(i,j) are cell arrays as well. max cannot operate on cell arrys directly and is erroring out. Modify the command to this:
b3{i,j}=max(b1{i,j},b2{i,j});
Also, for ilwt2 to work correctly b3,c3,d3 must be cell arrays. So you need to initialize them as b3 = cell(k1,k2);
I hope it fixes the issue.
Thanks
Sharmin

Sign in to comment.

Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!