MATLAB: [Help me,please] How to crop image, remove background of currency

backgroundboundarycropcurrencyedgeimageImage Processing Toolboxsegmentationwhite

Don't use imcrop(image,[]);
after (i crop with photoshop ^^).
Use boundary, edge...
Please help me, thank you for watching.
I am a beginer, i hope an answers.
My english is bad. @@

Best Answer

This code will do it:
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 color demo image.
folder = pwd;
baseFileName = 'bmbkK.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% 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.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
hsvImage = rgb2hsv(rgbImage);
sImage = hsvImage(:, :, 2);
subplot(2, 3, 2);
imshow(sImage, []);
title('Saturation Image', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2, 3, 3);
histogram(sImage);
grid on;
title('Histogram of Saturation Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Threshold.
mask = sImage > 0.1;
% Extract biggest blob.
mask = bwareafilt(mask, 1);
% Fill holes.
mask = imfill(mask, 'holes');
subplot(2, 3, 4);
imshow(mask);
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get bounding box.
props = regionprops(logical(mask), 'BoundingBox');
% Crop image.
croppedImage = imcrop(rgbImage, props.BoundingBox);
subplot(2, 3, 5);
imshow(croppedImage);
title('Cropped Image', 'FontSize', fontSize, 'Interpreter', 'None');
Related Question