Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Populating a matrix with pixel values

Subject: Populating a matrix with pixel values

From: m. k

Date: 31 Jul, 2007 17:04:56

Message: 1 of 3

Hello everyone.

I have a question, and I hope that someone out there can help me out. I am trying to use for loops to populate a matrix with pixel values from a given image.

Given an image, and an x and y coordinate, I want to generate a 5x5 matrix centered on (x,y), populated by pixel intensity values from the image.

A sample of my code:

for a = 0:6
   matrix(r,:)=image((y+2)-a, (x-2):(x+2));
   a=a+1;
end

Where matrix is the 5x5 matrix that I am trying to generate.

As you can see from the above code, I want to generate a 5x5 matrix, populating each matrix row wise, with the pixel intensity of the image based upon changing the coordinates. However, whenever I run this section of code in MatLab, the error i receive says:

??? Error using ==> image
Incorrect number of arguments specified.

Error in ==> generatematrix at 21
    clutter7(r,:)=image((y+3)-a,(x-3):(x+3));

I'm assuming that this message means that MatLab does not allow the image(x,y) command to retrieve information using the ':' operator. Am I wrong in this assumption? Does anybody knows if there is another way to automatically generate this matrix through the use of a for loop or some other operator?

Subject: Populating a matrix with pixel values

From: us

Date: 31 Jul, 2007 17:17:45

Message: 2 of 3

m. k:
<SNIP extracting data from an image...

one of the solutions

% the image
     img=reshape(1:25,[5,5]);
     rc=2; % submat center: row
     cc=4; % submat center: col
     ms=3; % submat size: 3x3 == odd
% the engine
     ns=floor(ms/2);
% ...error checking comes here!
     m=img(rc-ns:rc+ns,cc-ns:cc+ns);
% the result
     img
     m

us

Subject: Populating a matrix with pixel values

From: m. k

Date: 31 Jul, 2007 17:34:14

Message: 3 of 3

thanks for the help. i have another question though. how do i reshape the matrix if in your code, the '1:25' values were placed with pixel intensity values pulled from specific x and y coordinates from an image? Would you know how to pull those pixel values from an image and reshape them?

thanks,

m.k.

"us " <us@neurol.unizh.ch> wrote in message <f8nqrp$g01$1@fred.mathworks.com>...
> m. k:
> <SNIP extracting data from an image...
>
> one of the solutions
>
> % the image
> img=reshape(1:25,[5,5]);
> rc=2; % submat center: row
> cc=4; % submat center: col
> ms=3; % submat size: 3x3 == odd
> % the engine
> ns=floor(ms/2);
> % ...error checking comes here!
> m=img(rc-ns:rc+ns,cc-ns:cc+ns);
> % the result
> img
> m
>
> us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
obtaining the centre of image usuing pixel values R 21 Apr, 2008 02:09:26
code us 31 Jul, 2007 13:24:31
pixel m. k 31 Jul, 2007 13:05:07
image m. k 31 Jul, 2007 13:05:07
value m. k 31 Jul, 2007 13:05:07
population m. k 31 Jul, 2007 13:05:07
matrix m. k 31 Jul, 2007 13:05:07
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics