How to take pixels from an input image by using Gaussian sub-sampling (shotgun pattern like)?
1 次查看(过去 30 天)
显示 更早的评论
I want to take the locations of pixels that are to be taken like in a shotgun pattern concentrated in the middle of the image. Because I do not want to extract features of all pixels in an image. The output should be the coordinates of sampled pixels.
Is there any function or code that I can get help from that.
Your help is appreciated.
0 个评论
回答(1 个)
Image Analyst
2016-10-30
编辑:Image Analyst
2016-10-30
Try this:
% Initialization / clean-up code.
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 short g;
format compact;
fontSize = 20;
numPoints = 5000;
xCenter = 1000;
yCenter = 1000;
sigmax = 300;
sigmay = 600;
x = xCenter + sigmax * randn(numPoints, 1);
y = yCenter + sigmay * randn(numPoints, 1);
% Make sure that we get rid of points that would not be in the image.
outSideImage = x < 1 | y < 1
x(outSideImage) = [];
y(outSideImage) = [];
% Plot the points.
plot(x, y, 'b.', 'MarkerSize', 8);
grid on;
axis square
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% 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')
2 个评论
Image Analyst
2016-10-31
If I've answered the question, then can you "Accept this answer", otherwise, ask your followup question.
One thing to note is that if you're using the code to get row and column indexes, you'll need to round x and y to the nearest integer, and you'll also have to make sure x and y don't get bigger than the number of rows and columns in the image. Also be aware of that (x,y) is not (row, column). x is column, not row, so if you put this into a loop where you're extracting image values you'll need to do something like
for k = 1 : length(x)
row = y(k);
col = x(k);
pixelValue = grayImage(row, column);
end
DO NOT do
pixelValue = grayImage(x(k), y(k));
because the first index is not x. It's y. You could do
pixelValue = grayImage(y(k), x(k));
if you'd rather do that than use row and column.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!