2016-04-28 10 views
0

Extrahieren von unten habe ich ein binäres Bild, und ich will die Punkte der linken unteren Ecke dieses Foto bekommen:links in Bild in MATLAB

photo

(die, wo die roten Pfeil) . Insbesondere möchte ich die Koordinaten dieses Punktes erhalten.

EDIT: Ich, habe diese photo, und ich möchte die x, y-Koordinaten der Münzen zu bekommen und ihre Position relativ zur unteren linken Ecke. Hier ist mein Code und was ich bisher gemacht habe.

%% loading the image 
A=imread('as.jpg'); 
figure, imshow(A); 
K=rgb2gray(A); 
I=imrotate(K,90); 
[H,W]=size(I); 
figure, imshow(I); 
%% 
[visina,sirina]=size(I); 
sir=sirina(1)/5; 
P1=I(:,1:sir); 

%% cutting the photo in segments 

podelba=4; 
P=cell(podelba,1); 
pomN=sir; 
for n=1:4 
    pomK=sir+pomN; 
    P{n}=I(:,pomN:pomK); 
    pomN=pomK; 
end 

W=imrotate(([P1 P{1} P{2} P{3} P{4} ]),0); 
figure, imshow(W); 

%% threshold 
g1=im2bw(P1,graythresh(P1)); 
podelba1=4; 
G=cell(podelba,1); 
for i=1:4 
    G{i}=im2bw(P{i},graythresh(P{i})); 
end 

BW=~imrotate(([g1 G{1} G{2} G{3} G{4}]),0); 
figure, imshow(BW); 

%% noise reduction 
bw=bwareaopen(BW,20); 
se=strel('disk',2); 
bw=imclose(bw,se); 
bw=imrotate(imfill(bw,'holes'),-90); 
figure, imshow(bw); 

%% 
[B,L] = bwboundaries(bw,'noholes'); 
figure, imshow(bw); 
% Display the label matrix and draw each boundary 
imshow(label2rgb(L, @jet, [.5 .5 .5])) 
hold on 
for k = 1:length(B) 
    boundary = B{k}; 
    plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2) 
end 
%% 
stats = regionprops(L,'Area','Centroid'); 

threshold = 0.80; 

% loop over the boundaries 
for k = 1:length(B) 

    % obtain (X,Y) boundary coordinates corresponding to label 'k' 
    boundary = B{k}; 

    % compute a simple estimate of the object's perimeter 
    delta_sq = diff(boundary).^2; 
    perimeter = sum(sqrt(sum(delta_sq,2))); 

    % obtain the area calculation corresponding to label 'k' 
    area = stats(k).Area; 

    % compute the roundness metric 
    metric = 4*pi*area/perimeter^2; 

    % display the results 
    metric_string = sprintf('%2.2f',metric); 

    % mark objects above the threshold with a black circle 
    if metric > threshold 
    centroid = stats(k).Centroid; 
    plot(centroid(1),centroid(2),'ko'); 
    end 

%  text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',... 
%   'FontSize',14,'FontWeight','bold'); 

end 
+0

können Sie teilen, was Sie bereits tun versucht haben? Möchtest du die Punkte automatisch oder manuell erhalten? Wenn Sie manuell versuchen, versuchen Sie es imtool (https://www.mathworks.com/help/images/ref/imtool.html) – akamath

Antwort

1

Wenn Sie die Image Processing Toolbox haben, können Sie regionprops verwenden Sie den Schwerpunkt und die Liste der Pixel in jedem der verbundenen weißen Bereiche des Bildes zu geben.

%// Load image and convert to binary 
img = imread('http://i.stack.imgur.com/CAPB3.jpg'); 
img = img(:,:,1) > 50; 

%// Determine centroids of each connected component 
props = regionprops(img, {'Centroid', 'PixelIdxList'}); 

%// The lower left corner will have the centroid with the highest Y component 
centroids = cat(1, props.Centroid); 
[~, bottomLeftIdx] = max(centroids(:,2)); 

bottomLeft = props(bottomLeftIdx); 

Jetzt können Sie bottomLeft verwenden, um die Liste der Pixel zuzugreifen, die in diesem Block enthalten sind.

result = double(img); 
result(bottomLeft.PixelIdxList) = 2; 

imshow(result, []) 

enter image description here

+0

Ich habe meinen Code hochgeladen, werfen Sie einen Blick zurück. Danke vielmals. :) – aceace