Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Mean of intensities between 2 points

Subject: Mean of intensities between 2 points

From: Lee ZY

Date: 1 Aug, 2013 08:47:09

Message: 1 of 4

Hi, I would like to calculate the mean intensity of the area between 2 points in a matrix. for instance,

[URL=http://imageshack.us/photo/my-images/163/qck7.jpg/][IMG]http://img163.imageshack.us/img163/7348/qck7.jpg[/IMG][/URL]

Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]

I have 2 points at pixel-18 and pixel-28, I would like to know the value of
(val(18)+val(19)+val(20)+val(21)+val(25)+val(26)+val(27)+val(28))/8.

Points=pixel-5 and pixel-17
[URL=http://imageshack.us/photo/my-images/821/pox5.jpg/][IMG]http://img821.imageshack.us/img821/3728/pox5.jpg[/IMG][/URL]

Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]
mean=(val(3)+val(4)+val(5)+val(10)+val(11)+val(12)+val(17)+val(18)+val(19))/9

I've tried using the hard-coded way, but there are just too many possibilities plus it is not flexible at all when the range between the points is extended. Is there any better way to compute the result? Thanks in advance!

Subject: Mean of intensities between 2 points

From: Kevin Hellemans

Date: 1 Aug, 2013 13:15:07

Message: 2 of 4

"Lee ZY" wrote in message <ktd7ad$ocp$1@newscl01ah.mathworks.com>...
> Hi, I would like to calculate the mean intensity of the area between 2 points in a matrix. for instance,
>
> [URL=http://imageshack.us/photo/my-images/163/qck7.jpg/][IMG]http://img163.imageshack.us/img163/7348/qck7.jpg[/IMG][/URL]
>
> Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]
>
> I have 2 points at pixel-18 and pixel-28, I would like to know the value of
> (val(18)+val(19)+val(20)+val(21)+val(25)+val(26)+val(27)+val(28))/8.
>
> Points=pixel-5 and pixel-17
> [URL=http://imageshack.us/photo/my-images/821/pox5.jpg/][IMG]http://img821.imageshack.us/img821/3728/pox5.jpg[/IMG][/URL]
>
> Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]
> mean=(val(3)+val(4)+val(5)+val(10)+val(11)+val(12)+val(17)+val(18)+val(19))/9
>
> I've tried using the hard-coded way, but there are just too many possibilities plus it is not flexible at all when the range between the points is extended. Is there any better way to compute the result? Thanks in advance!

Try this:

%% Mean between two points
% define points
pt1 = 18;
pt2 = 28;

% Create your array
NumberedArray = reshape([1:1:35],7,5);

% Find pts in array
[x1,y1] = find(NumberedArray == pt1);
[x2,y2] = find(NumberedArray == pt2);

% Calculate mean
Mean2Pts = mean(mean(NumberedArray(x1:x2,y1:y2)));

Subject: Mean of intensities between 2 points

From: Kevin Hellemans

Date: 1 Aug, 2013 13:18:06

Message: 3 of 4

Try this:
%% Mean between two points
% define points
pt1 = 18;
pt2 = 28;

% Create your array
NumberedArray = reshape([1:1:35],7,5);

% Find pts in array
[x1,y1] = find(NumberedArray == pt1);
[x2,y2] = find(NumberedArray == pt2);

% Calculate mean
Mean2Pts = mean(mean(NumberedArray(x1:x2,y1:y2)));

Subject: Mean of intensities between 2 points

From: Lee ZY

Date: 2 Aug, 2013 01:28:10

Message: 4 of 4

"Kevin Hellemans" wrote in message <ktdn6e$2bv$1@newscl01ah.mathworks.com>...
> Try this:
> %% Mean between two points
> % define points
> pt1 = 18;
> pt2 = 28;
>
> % Create your array
> NumberedArray = reshape([1:1:35],7,5);
>
> % Find pts in array
> [x1,y1] = find(NumberedArray == pt1);
> [x2,y2] = find(NumberedArray == pt2);
>
> % Calculate mean
> Mean2Pts = mean(mean(NumberedArray(x1:x2,y1:y2)));

Thanks a lot Kevin. It works! will study about this
Thanks again!

Tags for this Thread

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.

Contact us