MATLAB Answers

Image Pixel Values

8 views (last 30 days)
Ishtiaq Bercha
Ishtiaq Bercha on 13 May 2011
[EDIT: 20110513 15:42 CDT - reformat - WDR]
Hi,
I am new to MATLAB and programing.
I am trying to write a program that performs some image analysis based on pixel values. If I want to determine the mean or max pixel value of image only I want to ensure that the background is removed and actual image is concentrated upon. I am going around this as follows:
x = 256
y = 256
J = dicomread('C:\Documents and Settings\122244\Desktop\DICOMF\IM_0064');
A=[];
for m = 1:x
for n= 1:y
if z = impixelinfo(m,n) >=1
A(m,n) = z
else continue
end
end
end
I will appreciate your tips. Also if you know of medical imaging related MATLAB books, then that would be of value.
Thanks,
---Ish
  2 Comments
Walter Roberson
Walter Roberson on 13 May 2011
Sean, Ishtiaq is expecting z to be assigned the value of impixelinfo(m,n), and then expecting that value to be compared to 1.
There are other languages where that would be a valid statement, but MATLAB isn't one of them.

Sign in to comment.

Answers (4)

Sean de Wolski
Sean de Wolski on 13 May 2011
If J is your image and you want the mean of all values greater than 10:
the_mean = mean(J(J>10));
You'll get a much more useful answer if you post your image with a specific question.
Welcome to MATLAB and Answers!

Matt Fig
Matt Fig on 13 May 2011
In addition to what others have said, this line:
if z = impixelinfo(m,n) >=1 % Are you sure about the 1?
is an incorrect use of IF statements. I think you mean:
z = impixelinfo(m,n);
if z>=1
In general, it looks like you want this (assuming J is an image):
J = dicomread('C:\Documents and Settings\122244\Desktop\DICOMF\IM_0064');
A = zeros(size(J),class(J));
A(J>=1) = J(J>=1); % Are you sure about the 1?
But note, that if your goal is only to obtain the mean, and you don't really need A for anything else, the Sean de has the preferred solution.

Walter Roberson
Walter Roberson on 13 May 2011
Your use of impixelinfo is incorrect. The two-argument form of impixelinfo is:
impixelinfo(hparent,himage) creates a Pixel Information tool in hparent that provides information about the pixels in himage. himage is a handle to an image or an array of image handles. hparent is a handle to the figure or uipanel object that contains the pixel information tool.
impixelinfo will not return the pixel value at a given offset: you need to index your image for that.
It is also not valid syntax to have an assignment as part of an "if" statement.

Nuwan Liyanage
Nuwan Liyanage on 1 Apr 2013
Hi everyone, I am new to MATLAB too and I will appreciate if anyone could give me an answer for my issue, which is somewhat similar to the original question in someways.
I want to take the pixel values of a ROI which can be defined by a user, to a matrix, and then I can take the average intensity value of that particular potion. this is also regarding mri image analysis. Using impixelinfo command, it gives all the values of the pixels in an image but I want to know a way to get that values into a matrix.
Thanks in advance.
Nuwan
  1 Comment
Image Analyst
Image Analyst on 1 Apr 2013
Please start your own thread and ask how mean2() can be used to calculate the mean of a 2D chunk of your image, and how imcrop() can be used to extract a chunk.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!