How label a line plotted automatically on an image?
Afficher commentaires plus anciens
Below is code Ive used to process a batch of images. The functions label white and dark regions on the image followed by plotting the necessary lines over the original data, identifying the segments. I'm looking to automatically label the plotted lines as 'Segment A' 'Segment B' etc, could anyone help me in doing so?
InputFolder = fullfile(pwd, 'FlatImages');
filePattern = fullfile(InputFolder, '*.bmp');
% Lists all BMP files in wd folder
BmpFiles = dir(filePattern);
OutputFolder = fullfile(pwd, 'SegmentedImages');
for i=1:length(BmpFiles)
fname = BmpFiles(i).name;
FullFileNameInput=fullfile(InputFolder, fname);
%Reads in each BMP file on by one
A=imread(FullFileNameInput);
[s f]=get_white_edges2(A);
[s1 f1]=get_Black_edges3(A);
Fname_out=['WE_' fname];
%Plots white and black edge segments on Flat Image
figure; imshow(A); hold on; plot([s f]); hold on; plot([s1 f1]);
FullFileNameOutput=fullfile(OutputFolder, Fname_out);
% -dbmp option with the PRINT command to save the
% figure as a BMP file. gcf returns current fig. handle.
print(gcf, '-dbmp', FullFileNameOutput);
end
Réponses (1)
Image Analyst
le 22 Fév 2015
0 votes
Use the text() function.
8 commentaires
Sean
le 22 Fév 2015
Image Analyst
le 22 Fév 2015
No. You don't have to manually place it. You can pass in the x,y location. I suggest you come up with some algorithm to get the x,y location, such as being at the midpoint of the line points.
Sean
le 22 Fév 2015
Image Analyst
le 22 Fév 2015
How about mean():
xMidpoint = mean(xArray);
yMidPoint = mean(yArray);
Or look at the range and pick the middle one
xMidpoint = 0.5 * (min(xArray) + max(xArray));
yMidPoint = 0.5 * (min(yArray) + max(yArray));
Sean
le 23 Fév 2015
Image Analyst
le 23 Fév 2015
Post an image so I can figure out what's going on. I don't see why you can't just figure out where the endpoints of the lines are.
Sean
le 23 Fév 2015
Sean
le 23 Fév 2015
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
