How to add a portion of image to another image

21 views (last 30 days)
Mohamed Elbeialy
Mohamed Elbeialy on 27 Aug 2020
Answered: Image Analyst on 27 Aug 2020
How to add different portion of flower's image to car's image

Answers (2)

Image Analyst
Image Analyst on 27 Aug 2020
See my attached copy and paste demos.
  3 Comments
Mohamed Elbeialy
Mohamed Elbeialy on 27 Aug 2020
Just add various pixels of flower's image into car's image to be one image. This part should be same size and pasted at top and bottom of car's image

Sign in to comment.


Image Analyst
Image Analyst on 27 Aug 2020
Try this. It will add the smaller image to the lower right part of the larger image.
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
rgbImage1 = imread('car.jpeg');
subplot(2, 2, 1);
imshow(rgbImage1);
[rows1, columns1, numberOfColorChannels1] = size(rgbImage1)
title('Image 1', 'FontSize', fontSize);
impixelinfo;
rgbImage2 = imread('pink flower.jpeg');
subplot(2, 2, 2);
imshow(rgbImage2);
[rows2, columns2, numberOfColorChannels2] = size(rgbImage2)
title('Image 2', 'FontSize', fontSize);
impixelinfo;
% Find out where the smaller flower image needs to be so that
% it will be in the lower right corner of the larger car image.
row3 = abs(rows1 - rows2) + 1
column3 = abs(columns1 - columns2) + 1
% Add them
sumImage = rgbImage1; % Initialize
subplot(2, 2, 3:4);
imshow(sumImage);
v = (double(rgbImage1(row3:end, column3:end, :)) + double(rgbImage2)) / 2;
sumImage(row3:end, column3:end, :) = uint8((double(rgbImage1(row3:end, column3:end, :)) + double(rgbImage2)) / 2);
subplot(2, 2, 3:4);
imshow(sumImage);
title('Image 1 + Image 2', 'FontSize', fontSize);
impixelinfo;

Community Treasure Hunt

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

Start Hunting!