image processing - MATLAB Auto Crop -
i trying automatically crop image below bounding box. background same colour. have tried answers @ find edges of image , crop in matlab , various applications , examples on mathworks' file exchange stuck @ getting proper boundingbox.
i thinking convert image black , white, converting binary , removing that's closer white black, i'm not sure how go it.
following answer of shai, present way circumvent regionprops (image processing toolbox) based on find
on black-white image.
% load img = im2double(imread('http://i.stack.imgur.com/zuiet.jpg')); % black-white image threshold on check how far each pixel "white" bw = sum((1-img).^2, 3) > .5; % show bw image figure; imshow(bw); title('bw image'); % bounding box (first row, first column, number rows, number columns) [row, col] = find(bw); bounding_box = [min(row), min(col), max(row) - min(row) + 1, max(col) - min(col) + 1]; % display rectangle rect = bounding_box([2,1,4,3]); % rectangle wants x,y,w,h have rows, columns, ... need convert figure; imshow(img); hold on; rectangle('position', rect);
Comments
Post a Comment