can,anyone provide me code for auto cropping and normalization of this image?pls..its urgent

1 view (last 30 days)
  1 Comment
Shubham Agrawal
Shubham Agrawal on 28 Nov 2014
yes,line has to crop also.. it is giving this error....
??? Undefined function or method 'bwconvhull' for input arguments of type 'char'.
Error in ==> Untitled at 15 binaryImage = bwconvhull(binaryImage, 'union');
pls fix it...also provide code for normalization

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 28 Nov 2014
Is the line on the left supposed to be in the cropped output? Assuming not, just crop that off.
grayImage = grayImage(:, 50:end);
Then threshold, take convex hull, label, call regionprops, and call imcrop. Here is some untested code.
binaryImage = grayImage < 128;
binaryImage = bwareaopen(binaryImage, 400); % Get rid of small specks.
binaryImage = bwconvhull(binaryImage, 'union');
measurements = regionprops(logical(binaryImage), 'BoundingBox');
boundingBox = measurements(1).BoundingBox; % Maybe the (1) is unnecessary???
croppedImage = imcrop(grayImage, boundingBox);
If that doesn't work and you can't figure out how to fix it, then post your code and screenshots, otherwise please mark the Answer as "Accepted".
  2 Comments
Shubham Agrawal
Shubham Agrawal on 28 Nov 2014
yes,line has to crop also.. it is giving this error....
??? Undefined function or method 'bwconvhull' for input arguments of type 'char'.
Error in ==> Untitled at 15 binaryImage = bwconvhull(binaryImage, 'union');
pls fix it...also provide code for normalization
Image Analyst
Image Analyst on 28 Nov 2014
Edited: Image Analyst on 28 Nov 2014
What does
>> which bwconvhull
say? Maybe you have an antique version of MATLAB, before that function was introduced. If so, you can upgrade (best option), or (sub-optimal option) you can sum the image horizontally and vertically to get the vertical and horizontal profile then threshold and use find() to find the starting and ending rows, and crop that way.
You didn't attach your code like I specifically asked, forcing me to do everything. OK, I did it all for you. I attached the code below the image it creates.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!