添加图像的方法是什么?

时间:2014-03-23 17:24:12

标签: image matlab

我正在使用此代码作为图像,使其第四季度等于零,然后需要在该季度添加新图像但以(二进制图像)的形式将是什么方式

clc
clear all
Q=imread('E:\stuff TOO\MATLAB\2rr.jpg');  % loading the image
R=rgb2gray(Q);                            % converting to grayscale
S=imresize(R,[600 600]);  % image resized for simpilcity of dividing(optional)
T=reshape(S,600,600);     % image divided into 4 equal quarter
U=mat2cell(T,[300 300],[300 300]);        % using thereshape & mat2cell codes
U1=0.*U{2,2};             % zeroto convert the quarter into a zero matrix(100x100)
V=[U{1,1} U{1,2}; U{2,1} U1];             % rebuilding the new image(matrix)
figure,imshow(R);
figure,imshow(V);

1 个答案:

答案 0 :(得分:0)

试试这个 -

%%// Read in the first image and convert to gray one as done in the original code
first_img = rgb2gray(imread(FILE1)); 

%%// Read in the second image as a binary image, which will be resized and 
%%// put into the fourth quad of the first iamge
second_img = im2bw(imread(FILE2)); 

%%// Get image sizes of the first image
[m,n,c] = size(first_img);

%%// Decide on the start row and column of the fourth quad
srow = m - round(m/2)+1;
scol = n - round(n/2)+1;

%%// Finally do the overlay
output_img = first_img;
output_img(srow:end,scol:end) = imresize(255.*second_img,[round(m/2) round(n/2)]);