Divide an image into n Sectors
Mostrar comentarios más antiguos
Hello,
I have an and I have to divide the image into 90 sectors that is each sector of 4 deg.
I found the centre this way :-
clc
clear
origIm = imread('1.bmp'); % test an image
bw = im2bw(origIm); % we use the image from thresholding
[height, width] = size(bw); % store the size of the image
centroid = ceil([height, width]./2); %get the center if the image
I need to find out the density and co-ordinates of all the black pixels in each sector and store them in a matrix. Can you help me with some code if possible ?
I am having trouble thinking how to work on it and get the density and specially co-ordinates of the pixels.
Thank you.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 18 de Abr. de 2014
Why do you need the coordinates of the black pixels? What are you going to do once you know them?
Many BMP images are color, even if they appear to be binary or grayscale. So you never use size() like you did. It's risky. See http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/ Steve's blog> for an explanation. Do this - it's much safer and more robust:
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
I thought of a different way than Jos. If you need it (i.e. only if his does not work), let me know.
6 comentarios
Ritz 1234
el 18 de Abr. de 2014
Image Analyst
el 18 de Abr. de 2014
You're going to have to define "something useful from that" more precisely if you are going to program it up. Why don't you show your images and tell us what you need to measure. I presume that you need to invent some new feature because none of the standard ones distinguish between two images that you know are different. But to give advice on that I'd need to see your images. You can attach them with the image icon above the edit box. And tell me what features you measured do not do a good job and force you to invent a new one.
Ritz 1234
el 19 de Abr. de 2014
Ritz 1234
el 29 de Abr. de 2014
Image Analyst
el 2 de Mayo de 2014
But you accepted an answer, so is this still a problem? If so, please answer my questions.
Ritz 1234
el 4 de Mayo de 2014
Jos (10584)
el 18 de Abr. de 2014
A slightly other approach:
Retrieve the indices of the black pixels using FIND
[r,c] = find(BW==0) % BW is a 2D array with zeros (black) and ones (white)
Now convert these indices into polar coordinate using cart2pol; subtract the origin (e.g., the centre of the picture [r0, c0]) first:
[theta, rho] = cart2pol(r-r0, c-c0)
Then you can count how many values of theta are within certain boundaries, using HISTC
Boundaries = linspace(0,2*pi,90) % 90 bins
N = histc(theta, Boundaries)
7 comentarios
Ritz 1234
el 19 de Abr. de 2014
Jos (10584)
el 20 de Abr. de 2014
doc find
doc cart2pol
doc linspace
doc histc
doc arrayfun
Ritz 1234
el 29 de Abr. de 2014
Jos (10584)
el 2 de Mayo de 2014
[N, idx] = N = histc(theta, Boundaries)
SegmentNumber = 3 ; % example
tf = idx == SegmentNumber ; % true for all thetas that fall within the segment
[theta(tf) r(tf) c(tf)] % corresponding indices r and c
Image Analyst
el 2 de Mayo de 2014
I just gave an answer where I divided an image into pie-shaped sector(s). Adapt this if you want: http://www.mathworks.com/matlabcentral/answers/127864#comment_211537 If you really need the (x,y) coordinates (which I doubt), then you can do
[blackRows, blackColumns] = find(~mask);
You'd have to explain why you need every single black pixel coordinate in an N by 2 list of (x,y) coordinates to me, because I've never needed that as far as I can recall.
Ritz 1234
el 4 de Mayo de 2014
Image Analyst
el 4 de Mayo de 2014
Sure, just go ahead and post it here.
Categorías
Más información sobre Read, Write, and Modify Image en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!