Calculate the mean of region with nonzero pixels

I have a mask with regions labeled with 1, 2 and 3. I have a 3D volume that I would like to calculate the mean of the pixels correspond to those regions.

I want to calculate the mean of the regions with number 1, number 2 and number 3 separately.

Is the following correct?

m = mean(volume(mask==1));

m = mean(volume(mask==2));

m = mean(volume(mask==3));

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

This requires a different approach altogether. You need to use one of the aggregating functions splitapply, accumarray or groupsummary. Assuming your mask is not a mask but a label image with integer values from 0 to N:

objectsmean = accumarray(double(mask(:))+1, yourimage(:), [], @mean);
%or
objectsmean = splitapply(@mean, yourimage(:), double(mask(:))+1);
%or
objectsmean = groupsummary(yourimage(:), mask, 'mean');

accumarray is probably the fastest. The double(..) is here in case your mask is stored as an integer type and the number of objects is equal to intmax(class(mask)) which would cause an overflow when 1 is added.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

--

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automating Queries In The Enhanced Jira Query Tool

Quantumblack(McKinsey) Coding test

Top 5 plugins for IntelliJ to boost your workflow

Understanding Git (Local Repo) and GitHub (Remote Repo)

How to manage microservices with dockers and git

How to Convert Lotus Notes to Outlook PST — A Perfect Solution

Testing Antennas with the LimeSDR Mini

Jackson API beyond ObjectMapper

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

More from Medium

How can I access the properties of the camera connected to

Classifying Flower through Sequential-API-Deep Learning.

Defining Key Terms and Concepts in Neural Networks (Part 2)

AI Hand Movement Recognition System — A quick guide