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!