how to combine image, using hold on in looping

조회 수: 3 (최근 30일)
faris fais
faris fais 2020년 10월 12일
답변: Satwik 2025년 3월 28일
hi everyone, i try to combine some image to be one but its doesnt work
i have 3 image
  1. its background image (orange color)
  2. its layer background
  3. its main image
i can combine the 1 and 2 with hold on
but if i try hold on in number 3, number 1 and 2 gone
imshow('background.png');
hold on;
bgimage = ['terbuka.png'];
[im1, map, alpha] = imread(bgimage);
f1 = imshow(im1);
set(f1, 'AlphaData', alpha);
plotcount=1
for k=1:3
for j=1:3
subplot(4, 4, plotcount);
plotcount=plotcount+1;
image2 = ['Star.png'];
[im, map, alpha] = imread(image2);
f = imshow(im);
set(f, 'AlphaData', alpha);
end
end
  댓글 수: 2
Image Analyst
Image Analyst 2020년 10월 14일
Please attach star.png, terbuka.png, and background.png.
faris fais
faris fais 2020년 10월 15일
background.jpg
terbuka.png
star.png

댓글을 달려면 로그인하십시오.

답변 (1개)

Satwik
Satwik 2025년 3월 28일
I understand that the aim is to overlay multiple images using MATLAB, but the issue arises when adding the third image, causing the previous images to disappear. This is likely due to the way 'subplot' is used, which creates new axes each time it is called, thus not preserving the previous images. Here is a modified version of the code which combines all the three images:
% Display the background image
imshow('background.png');
hold on; % Retain current plot
% Read and display the layer background image
bgimage = 'terbuka.png';
[im1, map, alpha] = imread(bgimage);
f1 = imshow(im1);
set(f1, 'AlphaData', alpha);
% Loop to overlay the main images
for k = 1:3
for j = 1:3
% Read and display the main image
image2 = 'Star.png';
[im, map, alpha] = imread(image2);
f = imshow(im);
set(f, 'AlphaData', alpha);
% Optionally, adjust the position of the images if needed
% For example, you can set the 'XData' and 'YData' properties
% to place images at specific locations.
% Example: set(f, 'XData', [x_position], 'YData', [y_position]);
end
end
Given below is the resulting image from the above script:
I hope this helps!

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by