Extracting information from a plot
3 ビュー (過去 30 日間)
古いコメントを表示
I have a map of objects on a basic plot. there are areas on the plot that don’t have many objects at all. I want to identify and extract these ‘void’ areas on my plot. I was thinking of setting a threshold of less than 5 objects per ‘degree’ on the plot will count as a ‘void’ area. How would I go about doing this?
3 件のコメント
採用された回答
Image Analyst
2016 年 1 月 7 日
You can create an image where you place a dot (set a pixel to a value of 1) wherever there is a data point. If the pixel is already set, then add 1 to the pixel value. Then you can scan it with a moving window with conv2() to count the dots in the window and find out where the count is less than some number. For example (untested)
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Create random data.
numPoints = 100000;
x = rand(1,numPoints);
y = rand(1, numPoints);
scaleFactor = 1000; % Adjust depending on the range of x and y.
% Aim to have rows and columns be around a thousand or so.
rows = ceil(max(y) * scaleFactor);
columns = ceil(max(x) * scaleFactor);
% Allocate empty array - no counts at all.
dotImage = zeros(rows, columns);
% Place dots in proper locations on our dot image.
for k = 1 : length(x)
row = ceil(scaleFactor * y(k));
col = ceil(scaleFactor * x(k));
dotImage(row, col) = dotImage(row, col) + 1;
end
subplot(2,2,1);
imshow(dotImage, []);
title('Dots Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Now count the dots in a 11-by-11 moving window
filterWindow = ones(11);
countsImage = conv2(dotImage, filterWindow, 'same');
subplot(2,2,2);
imshow(countsImage, []);
title('Counts Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% 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')
% Let's compute and display the histogram.
[pixelCount, grayLevels] = hist(countsImage(:), 30);
subplot(2, 2, 3);
bar(grayLevels, pixelCount); % Plot it as a bar chart.
grid on;
title('Histogram of counts image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize);
ylabel('Pixel Count', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Find out where the counts in the window is less than 50.
lowCountsImage = countsImage < 7;
subplot(2,2,4);
imshow(lowCountsImage, []);
title('Low Counts Map', 'FontSize', fontSize, 'Interpreter', 'None');
10 件のコメント
その他の回答 (1 件)
Walter Roberson
2016 年 1 月 7 日
Or you could do a 2D histogram.
I do not understand what you mean by 5 objects per degree in reference to a 2D plot: that would only make sense to me if you had a fixed origin point and you were more or less doing a radon transform.
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!