MATLAB Answers

Image Background Overlay Color Changes Why Does It happen?

1 view (last 30 days)
Mir AbdulRehman
Mir AbdulRehman on 12 Feb 2021
Answered: Selva Karna on 4 Mar 2021
Hi i just Worked on an Assignment and Im having some deficulties with it.....Canany one check whats wrong...
Note: Assignment is to modify the background image to display a Logo on it.
something like this,
I'm still new with Matlab please can anyone help me with this...
The code I have been working is the following.
% Some of the Functons were written in the assignment to use specifically like im2double and more.
% the starting is simple reading the image, resizing the logo image, and converting it to im2double, im2bw (Part of the assignment).
%I faced issues on the third where i have to use condition and for loop to chane the pixals valse one-by-one to display the logo
% on the background.
% Please help me with this assignment...
Bgimg = imread("Background_Image.jpg");
Bgimgdouble = im2double(Bgimg);
imshow(Bgimgdouble);
Fgimg = imread("Forground_Image.png");
FgimgRs = imresize(Fgimg, [576 720]);
imshow(Fgimg);
% converting White and Black to Black and White.
FgimgRsComp = imcomplement(FgimgRs);
imshow(FgimgRsComp);
Fgimg2bw = im2bw(FgimgRsComp, 0.4);
imshow(Fgimg2bw);
%Here im having some trouble
img = zeros(size(Fgimg2bw));
for ii=1:size(Fgimg2bw,1)
for jj=1:size(Fgimg2bw,2)
% get pixel value
pixel=Fgimg2bw(ii,jj);
% check pixel value and assign new value
if pixel<0.5
new_pixel=0;
elseif pixel>3
new_pixel=0;
else
new_pixel = pixel;
end
% save new pixel value in img image
img(ii,jj)=new_pixel;
end
end
imshow(img)
% When Place the image on to each other the logo image (VU) turns Blue instead of white.
% Also i wanted the logo to be transparent.
image(Bgimgdouble)
axis image
hold on
im = image(img);
im.AlphaData = max(img,[],3);
hold off
This is the Result im getting.....

Community Treasure Hunt

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

Start Hunting!