matlab - Copy an image to a bigger image -


i want copy sub image bigger image. have image1 , image2 image2 has size 600x300 , image1 has size 200x100. want copy image1 on image2, while rest of image2 remains. have tried -

`back_img = zeros(round(boundary_y),round(boundary_x),3); back_img = back_img(:,:,:);  [src_y, src_x,~] = size(img1); back_img(1:src_y, 1:src_x,1:3) = img1(1:src_y, 1:src_x,1:3); figure; imshow(back_img);` 

i have black background on top of want paste image. i'm getting white box image has there result. missing?

thanks!

main problem: back_img of class double , img1 of class uint8.
show image of class double displays pixels above 1 white pixels.
in uint8 class, pixel range [0, 255], when 255 white.

following code: back_img(1:src_y, 1:src_x,1:3) = img1(1:src_y, 1:src_x,1:3);, place uint8 matrix in matrix of class (type) double.
in case, matlab rule casting uint8 elements double.
using imshow(back_img) when back_img double, applies pixels range [0, 1] (0 black, , 1 white).
pixels above 1 white.
pixels of original uint8 image 1 or above, displyead white pixels after converting double.

solution: create 0 matrix in same class img1 (class uint8 in case).

check following code sample:

%prepeare 200x200 image example: img1 = imresize(imread('peppers.png'), [200, 200]);  boundary_x = 600; boundary_y = 600;  %back_img = zeros(round(boundary_y),round(boundary_x),3); %back_img = back_img(:,:,:); %do nothing...  %create 600x600x3 zeros matrix in smae class of img1 (in case img1 %uint8, class of back_img uint8 instead of double. back_img = zeros(round(boundary_y),round(boundary_x),3, class(img1));  [src_y, src_x, ~] = size(img1); back_img(1:src_y, 1:src_x,1:3) = img1(1:src_y, 1:src_x,1:3); figure; imshow(back_img); 

result:
enter image description here

result of original code:
enter image description here


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -