MATLAB: Removing background and superimpose pictures. I really need help on this problem! thanks for your help

image processingMATLABmatrix array

%Task 1 - Load image1.jpg and create figure 1
disp('Task 1 See figure 1, image1.jpg');
I=imread('image1.jpg');
figure(1);
image(I);
pause
%Green component
disp('Green component');
G = I(:,:,2);
image(G),colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]);
pause
i attach the image. what code should i write to prompt a number between 0 and 255 next? Use the matrix from green component to create new matrix with size n x n; new matrix with size m x n x 3; and replace original image with white background.

Best Answer

You can try this code to ask the user for a number. It rounds any floating point number to the nearest integer but gives a warning if they don't enter a number (like they entered "five" or something).
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
Related Question