clc; close all;
img = imread('29_11_2019_164105.jpg');
pathName = "C:\Users\ezxtg4\Downloads\JPEG pics\crops\";
[counts, ~] = imhist(rgb2gray(img), 255);
T = otsuthresh(counts);
BW = imbinarize(rgb2gray(img), T);
BW2 = bwareaopen(BW, 3000);
BW2 = imfill(BW2, 'holes');
BW2 = bwperim(BW2);
BW2 = imdilate(BW2, ones(5));
BW2 = imerode(BW2, ones(3));
[L, n] = bwlabel(BW2);
for i = 1:n
I4 = L==i;
I5 = imfill(I4,'holes');
I6 = img.*repmat(uint8(I5),[1 1 3]);
I6 = imclearborder(~I6);
imwrite(I6, fullfile(pathName, sprintf('crop %d.jpeg', i)));
end
4 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799463
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799463
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799474
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799474
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799482
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799482
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799492
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/506343-how-can-i-centre-points-of-interest-in-an-image-before-it-s-cropped-and-saved#comment_799492
Sign in to comment.