how to crop a binary image horizontally if vertical length exceeds a certain value?

I have a couple of binary images depicting hand gestures. There are some side effects in those images, that is, images include arm part (down the wrist till elbow). Please view the images attached! I am going to crop this part according to some condition. Is there any way of writing a code for this?
For example: finding the vertical center of white region, or, finding the vertical length of the white region and cut out the bottom part percentage-wise?
Please note that the content of an image (hand) may have different verticality like in the 3rd attached image, so a suggested method should consider up to 40 % curvature as vertical.
Thank you for your ideas!

 Accepted Answer

I = imread('1.jpg') ;
[y,x] = find(I) ;
L = max(x)-min(x) ;
B = max(y)-min(y) ;
Icrop = imcrop(I,[min(x) min(y) L B]) ;
Crops only the region of interest.

4 Comments

Thank you for this, but what I want is not this. I have to get rid out of the bottom part of the hand itself, not black space. Let's say I have this image below:
Then a provided method should output something like this:
As you see, the bottom part of a hand is black now. If the vertical distribution of pixels is longer than a certain length it should cut the bottom part... Or something that does the same...
I = imread('3.jpg') ;
imshow(I) ;
[I2,Rect] = imcrop(I) ;
idx1 = round(Rect(1)) ;W = round(Rect(3)) ;
idy1 = round(Rect(2)) ;H = round(Rect(4)) ;
x = idx1:idx1+W ;
y = idy1:idy1+H ;
[X,Y] = meshgrid(x,y) ;
I(X,Y) = 0 ;
imshow(I) ;
When prompted, select the part which you want to remove/ convert to black.
Sir, in this way I have to manually select the region, but still it is not what I want. It should automatically remove if the image exceeds a certain vertical length. The longer the image vertically is the more part from bottom should be cut.
Thank you anyway!
Try this:
I = imread('3.jpg') ;
imshow(I) ;
[y,x] = find(I) ;
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
%%Form a rectangle
B = x1-x0 ; % horizontal length
L = y1-y0 ; % vertical length
L0 = 200 ; % specified length, change as you wish
if L > L0
dL = L-L0 ;
end
I(x0+dL:end,:) = 0 ;
imshow(I)

Sign in to comment.

More Answers (0)

Asked:

on 8 May 2017

Commented:

on 11 May 2017

Community Treasure Hunt

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

Start Hunting!