Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- img = imread('test7.png');
- bw = im2bw(img, 0.9);
- bw = ~bw;
- % matlabpool open
- rots = 1:16; % todo: zwiększyć do 1:360. Niech się komp męczy, a co!
- rot2area = zeros(size(rots));
- rotang=360/size(rots,2);
- parfor i=rots
- imm = imrotate(bw, i*rotang);
- % szumy won
- L = bwlabel(imm);
- s = regionprops(imm, 'Area');
- area_values = [s.Area];
- idx = find(5 < area_values);
- imm = ismember(L, idx);
- % pole otoczki
- [r,c] = find(imm);
- height = max(r)-min(r);
- width = max(c)-min(c);
- rot2area(i) = height * width;
- end
- % dobieramy najlepsze obroty
- [~,rots] = sort(rot2area);
- rots = rots(1:4);
- imm = imrotate(bw, rots(4)*rotang);
- % odszumiamy raz jeszcze
- L = bwlabel(imm);
- s = regionprops(imm, 'Area');
- area_values = [s.Area];
- idx = find(5 < area_values);
- imm = ismember(L, idx);
- % to nic nie daje, przynajmniej dla testowego tekstu
- %imm = imerode(imm, strel('rectangle',[1,1]));
- s = regionprops(imm, 'Centroid', 'BoundingBox');
- cents = cat(1,s.Centroid);
- bgbox = cat(1,s.BoundingBox);
- [width,~] = size(imm);
- SE = strel('line', width*width,0);
- imm2 = imdilate(imm,SE);
- linesp = regionprops(imm2, 'BoundingBox');
- lines = cat(1,linesp.BoundingBox);
- imshow(imm)
- hold on
- plot(cents(:,1), cents(:,2), 'b+')
- idx = find(bgbox(:,3) < 1.5 * bgbox(:,4)); % indeksy połączonych
- unrec = {};
- unrec_i = 1;
- for i=1:size(lines,1)
- rectangle('Position', lines(i,:), 'Curvature', [0,0], 'EdgeColor', 'y');
- end
- for i=1:size(bgbox,1)
- if not(ismember(i, idx))
- rectangle('Position', bgbox(i,:), 'Curvature', [0,0], 'EdgeColor', 'r');
- x = ceil(bgbox(i,1));
- y = ceil(bgbox(i,2));
- w = ceil(bgbox(i,3))-1;
- h = ceil(bgbox(i,4))-1;
- unrec{unrec_i} = imm(y:y+h, x:x+w);
- unrec_i = unrec_i + 1;
- else
- rectangle('Position', bgbox(i,:), 'Curvature', [0,0], 'EdgeColor', 'g')
- end
- end
- hold off
- % % szumy won
- % L = bwlabel(bw);
- % s = regionprops(L, 'Area');
- % area_values = [s.Area];
- % idx = find(5 < area_values);
- % bw = ismember(L, idx);
- % imshow(bw)
- %
- % % oblicz otoczkę wszystkiego
- % [r,c] = find(bw);
- % height = max(r)-min(r);
- % width = max(c)-min(c);
- % area = height * width;
- %rots = 1:2;
- %t_im1rs = zeros(size(rots,2),1);
- %for angle = rots
- % t_im1rs(angle) = 0; %imrotate(t_im1, angle);
- % tmp = regionprops(imrotate(im, angle), 'BoundingBox');
- % [ul_corner, width] = tmp.BoundingBox
- %end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement