How can i find lines in Star patterns ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi . I have a kind of pictures that refer to the radiotherapy sets , star patterns . I want to find lines(central lines) in these pictures . seems picture :

someones help me , please
3 Commenti
Image Analyst
il 28 Apr 2018
Exactly what does "find" mean to you? How about thresholding to find all the dark pixels? How about using hough() (follow the demo in the help)? Or do you want the dark lines thinned to a single pixel wide? Or do you want an analytical formula for y=f(x)? Or do you want the two endpoints of the line segments? Please explain what "find" means to you.
Risposte (2)
Image Analyst
il 29 Apr 2018
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
fullFileName = 'D:\Matlab\work\Tests\star8.jpg';
[folder, baseFileName, ext] = fileparts(fullFileName);
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Shrink it to speed it up
% rgbImage = imresize(rgbImage, 0.75);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(2, 3, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Convert to a grayscale image
grayImage = rgbImage(:, :, 3);
% Display the original image.
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
caption = sprintf('Gray Scale Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Compute the histogram
subplot(2, 3, 3);
histogram(grayImage, 'BinWidth', 1);
grid on;
% Find the big central blob
mask = grayImage < 239;
% Display the mask image.
subplot(2, 3, 4);
imshow(mask, []);
axis on;
caption = sprintf('Thresholded image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Do an opening to eliminate the spokes
se = strel('disk', 11, 0);
mask = imopen(mask, se);
% Extract just the biggest blob.
mask = bwareafilt(mask, 1);
% Do a dilation to grow it more.
mask = imdilate(mask, true(5));
% Display the mask image.
subplot(2, 3, 5);
imshow(mask, []);
axis on;
caption = sprintf('Eroded Mask');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Create a mask again without the central blob
mask2 = grayImage < 239 & ~mask;
% Extract just the 14 biggest blobs.
mask2 = bwareafilt(mask2, 14);
[labeledImage, numberOfLines] = bwlabel(mask2);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
% Display the mask image.
subplot(2, 3, 6);
imshow(coloredLabels, []);
axis on;
caption = sprintf('Mask of 14 blobs');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
props = regionprops(labeledImage, 'PixelList');
% For each blob, fit the x and y to a line
for k = 1 : numberOfLines
thisX = props(k).PixelList(:, 1);
thisY = props(k).PixelList(:, 2);
% Fit to a line
coefficients = polyfit(thisX, thisY, 1);
slope(k) = coefficients(1);
intercept(k) = coefficients(2);
end
% Bring up the original image.
figure;
subplot(1, 2, 1);
imshow(grayImage);
axis on;
hold on;
% For exvery pair, determine where they cross
for k1 = 1 : numberOfLines
for k2 = 1 : numberOfLines
x(k1, k2) = (intercept(k2) - intercept(k1)) / (slope(k1) - slope(k2));
y(k1, k2) = slope(k2) * x(k1, k2) + intercept(k2);
plot(x(k1, k2), y(k1, k2), 'r+', 'MarkerSize', 10);
end
end
title('Line Crossings', 'FontSize', 20);
x(isnan(x)) = [];
y(isnan(y)) = [];
% Find centroid of them all
xCenter = mean(x(:), 'omitnan');
yCenter = mean(y(:), 'omitnan');
% Find distances
distances = sqrt((x(:) - xCenter) .^ 2 + (y(:) - yCenter) .^ 2);
isAnOutlier = isoutlier(distances);
% Exclude outliers
x = x(~isAnOutlier(:));
y = y(~isAnOutlier(:));
% Get the mean of the non-outliers
xMean = mean(x, 'omitnan')
yMean = mean(y, 'omitnan')
subplot(1, 2, 2);
imshow(grayImage);
axis on;
hold on;
plot(xMean, yMean, 'r+', 'MarkerSize', 20, 'LineWidth', 2);
title('Centroid Plotted', 'FontSize', 20);


0 Commenti
Vedere anche
Categorie
Scopri di più su Blue in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
