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

2 views (last 30 days)
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. @@
  6 Comments
Jan
Jan on 26 Jun 2017
@Lee Bruce: Everything is fine. I did not make the laws and I think they are not really smart. It is just a good idea to ask, before the forum assists you to get into troubles.
Let's trust your teacher.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 26 Jun 2017
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');

More Answers (1)

Jan
Jan on 26 Jun 2017
Do you have the Image Processing Toolbox and are you allowed to use it? You need a threshold at first to create a BW image. What about converting the RGB image to HSV colorspace, such that the grey/white pixels can be identified easily? Then a few pixels might be detected inside the banknote. which could be removed by a median filter. Finally regionprops with the 'BoundingBox' property might help. But you can search for the maximum and minimum rows and columns by find also.
Note that this forum does not post solutions of homework questions usually for good reasons. So try it and ask a specific question.
  3 Comments
Jan
Jan on 26 Jun 2017
You have a GUI already. What are the inputs for the question you ask here? The filename or the image data? What have you tried so far? Giving suggestions for improvements is much easier than guessing, what you exactly need. So please explain explicitely, how we can help you.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!