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

%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.

 Réponse acceptée

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

2 commentaires

thanks. how can i create new matrix with "number of pixels" x "number of pixels" size and m x n x 3 size.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
or, to create a "zero" image
rgbImage = zeros(rows, columns, 3, 'uint8');

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by