Does regionprops function work in Matlab App designer

1 view (last 30 days)
mriadjust = app.mri; % create a copy of the dataset
ub = app.upper_bound;
lb = app.lower_bound;
l=repmat(int16(0), [256 256 20]);
mriadjust(mriadjust <= lb) = 0; % segment out pixels w/ intensities lower than ub
mriadjust(mriadjust >= ub) = 0; % segment out pixels w/ intensities greater than lb
bw = logical(mriadjust); %binary conversion
%morphological opening
nhood = ones([7 7 3]);
bw = imopen(bw,nhood);
%isolate the largest region
l = bwlabeln(bw); %label the objects in the image
stats = regionprops(l,'Area','Perimeter'); %use the regionprops function to gather info on the objects
A = [stats.Area]; % copy the area informaton about the objects to the variable A
biggest = find(A == max(A)); % find the object with the largest area in the image
stats.Area
stats.Perimeter
mriadjust(l ~= biggest) = 0; % any object that is not the largest object gets removed
imA = imadjust(mriadjust(:,:,10));
figure
imshow(imA);
/////////////////////
Above is my code for segmenting MRI brain scans. I'm trying to implement the code into app designer but it always gives me the error array sizes don't match for ~= operation. I figured out it was because there was no values in my stats, A, or biggest variables. I suspect it is because regionprops is not working in the appdesigner. Is there a way around this?

Accepted Answer

Simon Chan
Simon Chan on 7 Mar 2022
You are extracting something less than or equals to the lower bound (example < 100), and then extracting the resulting image with pixel greater than or equals to upper bound (example > 200). Then there is nothing left.
Modify the following
mriadjust(mriadjust <= lb) = 0; % segment out pixels w/ intensities lower than ub
mriadjust(mriadjust >= ub) = 0; % segment out pixels w/ intensities greater than lb
to
mriadjust(mriadjust <= ub) = 0; % segment out pixels w/ intensities lower than ub
mriadjust(mriadjust >= lb) = 0; % segment out pixels w/ intensities greater than lb

More Answers (1)

Matt J
Matt J on 7 Mar 2022
The reason is that your bw is all zeros. Nothing to do with app designer.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!