Crop image in diagonal direction
6 views (last 30 days)
Imcrop allows us to select a rectangular region that we can later on crop.
However,given an image as shown below,the result of imcrop is not always sufficient.I would like to know ,if there is a way to perform the cropping at an angle.
The result of imcrop on this is as follows(i am interested in getting m,a,j ,o ri and ty)
As we can see that some part of the o has been included in this.So that's why I am looking for a better cropping method.
Note i tried regionprops,but unfortunately all the images are subjected to a bw operation which is not what i want.
Nor do i want imfreehand as i wasn't able to get the correct results.
DGM on 17 Aug 2021
Edited: DGM on 17 Aug 2021
This isn't really a complete solution, but oh well.
Just because regionprops does binarization doesn't mean that the result needs to be binary. You can use the mask to select regions from the image. The masks don't even necessarily need to have hard edges. For example:
cl = bwlabel(c);
bb = vertcat(S.BoundingBox);
maxbb = max(bb(:,[4 3])); % minimal box geometry
maxbb = maxbb+5; % add some extra room
numchars = numel(S);
tp = round(S(j).BoundingBox);
xrange = tp(1)+(-1:tp(3)+1);
yrange = tp(2)+(-1:tp(4)+1);
% start out with no masking
target = a(yrange,xrange);
% use a dilated mask
tm = double(imdilate(cl(yrange,xrange)==j,ones(3)));
% apply the mask
target = im2uint8(im2double(target).*tm + ones(size(tm)).*(1-tm));
% this pads with black to match sizes
bs = (maxbb-size(target))/2;
target = padarray(target,floor(bs),255,'pre');
target = padarray(target,ceil(bs),255,'post');
Now of course, segmenting by region connectivity isn't going to solve the problem. There's no trivial way to break apart multiple letters made with the same stroke, and there's no way to associate the dots with their corresponding characters. How is that done? Fancier binary segmentation? Polygonal ROI's? I don't know, but using imcrop() isn't the answer.