cover another image by multiple image with exactly position ?

Dear All,
I am doing my study thesis and I got problem that I don't know how to overlay current image to other image with exactly position.
The position was generate when i detect the centroid. (it can be seen in the stat variable in workspace after run my code)
Could any expert help me please ?
another image is 'Original.jpg' that i attached to this post
This is my code:
Ibw = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/999460/finalmask.png');
stat = regionprops(Ibw,'Centroid');
imread(("https://www.mathworks.com/matlabcentral/answers/uploaded_files/999465/original.jpg"));
imshow(imread(("https://www.mathworks.com/matlabcentral/answers/uploaded_files/999465/original.jpg")))
hold on;
N=numel(stat);
for i=1:N
stat(i).BoundingBox=[stat(i).Centroid-32.5, 63,63];
plot(stat(i).Centroid(1),stat(i).Centroid(2),'+',LineWidth=2);
end
hold off
I2=imread("https://www.mathworks.com/matlabcentral/answers/uploaded_files/999465/original.jpg")
subimages=arrayfun(@(s)imcrop(I2,s.BoundingBox), stat,'uni',0); %You can use a new image here
montage(subimages,'Back','w','Bor',0)
for k = 1:N
b{k}=cell2mat(subimages(k,1))
filename=sprintf('image0%d.jpg',k)
imwrite(b{k},filename)
end
Thanks and Regards
Han

 Réponse acceptée

Image Analyst
Image Analyst le 16 Mai 2022
Try imoverlay and see if that's what you want.

2 commentaires

Thanks @Image Analyst It work ! But I still need to overlay by defined position (x,y)
Could you help me to put overlay image by exactly position ( position by x and y in structure array). I attached the background image and image01-09 for overlay.
This is my structure array for position:
location= {[660.517027863777,272.693498452012]
[684.704545454546,864.170454545455]
[696.189542483660,541.529411764706]
[732.700000000000,626.183333333333]
[743.694805194805,360.623376623377]
[798.042253521127,728.281690140845]
[837.595943837754,475.669266770671]
[861.016103059581,301.373590982287]
[897.675126903553,370.913705583756]}
fields = ('position')
location_of_image = cell2struct(position, fields, 2);
If you don't have a binary image then imoverlay would not be what you want. If you have gray scale images then you may just want to paste them onto the image, covering up what was there before. See attached demo.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by