2

I'm trying to implement an algorithm that needs a circular sliding window, that goes through all the pixels of the image, and for each window I need to extract only pixels that lay on diameters at different angles of the circle.

enter image description here

I try to explain better with the use of the image above. Imagine that this is the result of a circular sliding window, I want to get only the pixel values that lay on the red line (diameter tilted of pi/8).

So far, I wrote these lines of code:

I= imread('lena.png'); 
I = im2double(I);
h = fspecial('disk',5);
h = h > 0;
dir = pi/8;
o_image = blockproc(I, [1 1], @(x) MMF2D(x,h,dir), 'BorderSize', [5 5],...
'TrimBorder', false, 'PadPartialBlocks', true);

and the function MMF2D:

function [ o_pixel ] = MMF2D( i_block, i_window, i_directions)
%MMF2D Summary of this function goes here
%   Detailed explanation goes here

new_block = i_block.data .* i_window;

But from here, I don't know how to continue for getting pixels that lay on diameter. The diameter can be tilted of any angle. Any help is greatly appreciated!

BugsFree
  • 540
  • 1
  • 6
  • 24
  • 1
    isn't it simpler to transform to polar coordinates and then just scan angles vs radius ? – bla Jul 08 '15 at 16:55
  • I don't have clue, thus any idea could be interesting and simpler and better than mine. Could you explain a little bit better your idea? Thank you. – BugsFree Jul 08 '15 at 18:55
  • let me just understand you. You want that for every pixel, you have the values of pixels that are on a mask represented by the red lines? – bla Jul 08 '15 at 20:27

1 Answers1

1

Here's what I'd do:

First create the mask (you can put this into a function if you want), and get the relevant pixels indices as function of angle:

%% create mask and get indices as function of angle
o=5;
m=zeros(2*o+1);
m(o+1,:)=1;
theta=0:15:90; % in degrees, theres no need to go beyond 90 deg becuase of symmetry
for n=1:numel(theta)
   id{n}=find(imrotate(m,theta(n),'nearest','crop'));
end;

I use a cell array because there can be different number of indices per angle.

Then read image

I= imread('http://scipy-lectures.github.io/_images/lena.png'); 

Rearrange image blocks into columns

B = im2col(I,[2*o+1 2*o+1],'sliding');

what you want is just:

for n=1:numel(theta)
    C{n} =  B(id{n},:);
end

each cell element in C represents the pixels that were on a diameter of length 2*o+1 at an angle theta that was per-defined, for each pixel in the image.
So C{1} will give you all the pixels for theta=0, and C{2} for theta=15 etc...

bla
  • 25,846
  • 10
  • 70
  • 101
  • Thank you! You solved this example, but I realized that I didn't explain in the correct way may problem. I need to be able get the pixels on a single diameter per time, and this diameter can be tilted of any angle. – BugsFree Jul 09 '15 at 10:03
  • I edited the question to try to explain better. Probably your first idea with the polar coordinates was correct, but I don't know how to implement it. – BugsFree Jul 09 '15 at 13:18
  • what would you expect the output to look like? – bla Jul 09 '15 at 16:20