i need a code for compare a image captured by webcam and the images saved on a folder
MATLAB: Hi how i can compare a image captured by webcam and the images saved on a folder
Image Processing Toolbox
Related Solutions
Stitch them together, like this:
% First need to make the binary image in the range 0-255 instead of 0-1 so you can see it.
binaryImage = 255 * uint8(binaryImage);stitchedImage = [grayImage, binaryImage];imshow(stitchedImage, []);
Here's a full blown demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');baseFileName = 'cameraman.tif';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendgrayImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);if numberOfColorBands > 1 % It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end% Display the original gray scale image.
subplot(1,2,1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') % Create a binary image by thresholding.
binaryImage = grayImage > 100;subplot(1,2,2);imshow(binaryImage, []);title('Binary Image', 'FontSize', fontSize);% Create a new figure window.
figure;% Stitch them together.
% First need to make the binary image in the range 0-255 instead of 0-1 so you can see it.binaryImage = 255 * uint8(binaryImage);stitchedImage = [grayImage, binaryImage];imshow(stitchedImage, []);title('Stitched Image', 'FontSize', fontSize);% Enlarge figure to full screen.set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);% Give a name to the title bar.set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;%===============================================================================
% Read in a standard MATLAB gray scale demo image.
folder = pwd;baseFileName = 'PAR1_1.jpg';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage);% Display the image.
subplot(2, 2, 1);imshow(rgbImage, []);title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') grayImage = rgb2gray(rgbImage);binaryImage = imfill(grayImage ~= 255, 'holes');binaryImage = bwareafilt(binaryImage, 1); % Extract only the largest.
% Display the image.subplot(2, 2, 2);imshow(binaryImage, []);title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');labeledImage = bwlabel(binaryImage);props = regionprops(labeledImage, 'BoundingBox');% Crop the image
croppedImage = imcrop(grayImage, props.BoundingBox);% Display the image.subplot(2, 2, 3:4);imshow(croppedImage, []);title('Cropped Image', 'FontSize', fontSize, 'Interpreter', 'None');
Best Answer