inpict = imread('image.png');
inpict = im2gray(inpict);
mask0 = inpict >= 25 & inpict <= 110;
mask0 = bwareafilt(mask0,1);
mask0 = imfill(mask0,'holes');
mask0 = imopen(mask0,strel('disk',11));
P = houghpeaks(H,4,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(mask0,T,R,P,'FillGap',1000,'MinLength',10);
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
p1 = vertcat(lines.point1);
th = vertcat(lines.theta);
p0 = 1000*[cosd(th(k)+90) sind(th(k)+90)] + p1(k,:);
p2 = 1000*[cosd(th(k)-90) sind(th(k)-90)] + p1(k,:);
E = E | brline_forum(sz,[p0; p2]);
E = bwmorph(E,'branchpoints');
V = regionprops(E,'centroid');
th = atan2d(V(:,2)-C(2)/2,V(:,1)-C(1)/2);
mask = poly2mask(V(:,1),V(:,2),sz(1),sz(2));
inpict = imread('image.png');
inpict = im2gray(inpict);
mask0 = inpict >= 25 & inpict <= 110;
mask0 = bwareafilt(mask0,1);
mask0 = imfill(mask0,'holes');
mask0 = imopen(mask0,strel('disk',11));
roivalues = inpict(mask0);
inpict = imread('image.png');
inpict = im2gray(inpict);
V = [114 16; 130 258; 366 259; 379 11];
mask = poly2mask(V(:,1),V(:,2),sz(1),sz(2));
inpict = imread('image.png');
inpict = im2gray(inpict);
boxm = [114 16; 130 258; 366 259; 379 11];
boxf = [1 1; 1 szo(1); szo(2) szo(1); szo(2) 1];
TF = fitgeotrans(boxm,boxf,'projective');
outpict = imwarp(inpict,TF,'fillvalues',0,'outputview',outview);