?? imbackground.m
字號:
function back_image = imbackground(img, lightback)
% Image Background, (Adam Meadows: ameadows@cs.ucr.edu)
% back_image = imbackground(img, lightback)
%
% IMG is the input image
% LIGHTBACK is a flag specifying that the background is lighter than the foreground
%
% BACK_IMAGE returns the blank background image with the same dimensions as IMG
%
%convert to binary image
I = rgb2gray(img);
bw = im2bw(I, graythresh(I));
%if a light background, swap the values of bw
if(lightback == 1)
bw = swap(bw);
end %end of if it was a light background
%variables to hold RGB info for all background pixels, and count
R = uint32(0);
G = uint32(0);
B = uint32(0);
numPixels = 0;
%now loop through the binary image, only considering coordinates == 1
[r c] = size(bw);
while (numPixels < 1000)
i = floor(rand * r);
if(i == 0)
i = 1;
end
j = floor(rand * c);
if(j == 0)
j = 1;
end
if(bw(i,j) == 0)
numPixels = numPixels + 1;
R = R + uint32(img(i,j,1));
G = G + uint32(img(i,j,2));
B = B + uint32(img(i,j,3));
end %end of if it's a background pixel
end %end of outer loop
R = floor(R / numPixels);
G = floor(G / numPixels);
B = floor(B / numPixels);
%create the background image
back_image = img;
back_image(:,:,1) = R;
back_image(:,:,2) = G;
back_image(:,:,3) = B;
%end %end of find_back function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -