How to take pixels from an input image by using Gaussian sub-sampling (shotgun pattern like)?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Image Analyst
am 30 Okt. 2016
Bearbeitet: Image Analyst
am 30 Okt. 2016
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 Kommentare
Image Analyst
am 31 Okt. 2016
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.
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!