How to crop the gray scale image automatically???

1 回表示 (過去 30 日間)
Mohammad Bhat
Mohammad Bhat 2018 年 3 月 11 日
コメント済み: Akira Agata 2018 年 3 月 12 日
Hi, I have a gray scale image of Handwritten word, I want to crop only portion of that image which exactly carries that word or information , overthrow another region , how can I do that, figures are attached...

回答 (1 件)

Akira Agata
Akira Agata 2018 年 3 月 12 日
How about the following script?
I = imread('1.jpg');
BW = imbinarize(I);
BW1 = bwconvhull(~BW);
s = regionprops(BW1,'BoundingBox');
I2 = imcrop(I,s.BoundingBox);
  2 件のコメント
Mohammad Bhat
Mohammad Bhat 2018 年 3 月 12 日
I got following errors while following your commands:
Error using regionprops>getPropsFromInput (line 1223) Expected input number 1, PROPERTIES, to match one of these strings:
'Area', 'Centroid', 'BoundingBox', 'SubarrayIdx', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Orientation', 'ConvexHull', 'ConvexImage', 'ConvexArea', 'Image', 'FilledImage', 'FilledArea', 'EulerNumber', 'Extrema', 'EquivDiameter', 'Solidity', 'Extent', 'PixelIdxList', 'PixelList', 'Perimeter', 'PerimeterOld', 'PixelValues', 'WeightedCentroid', 'MeanIntensity', 'MinIntensity', 'MaxIntensity'
The input, 'BoundingBox ', did not match any of the valid strings.
Error in regionprops>ParseInputs (line 1188) reqStats = getPropsFromInput(startIdxForProp, ...
Error in regionprops (line 154)
[I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
Akira Agata
Akira Agata 2018 年 3 月 12 日
During your copy&paste, a space seems to be mistakenly inserted.
Correct input:
s = regionprops(BW1,'BoundingBox');
Wrong input:
s = regionprops(BW1,'BoundingBox ');

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by