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);
- imshow(imm)
- hold on
- %plot(cents(:,1), cents(:,2), 'r*')
- %idx = find(bgbox(:,3) < 1.5 * bgbox(:,4)); % indeksy połączonych
- idx = find(bgbox(:,3) < 1.5 * bgbox(:,4)); % indeksy połączonych
- for i=1:size(bgbox,1)
- if ~ismember(i, idx)
- rectangle('Position', bgbox(i,:), 'Curvature', [0,0], 'EdgeColor', 'r')
- 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