Why do I get this error of the '=' operator? I am trying to get the individual mean values of the blobs of pixels (in the image there are blobs of pixels and I want each mean)

1 view (last 30 days)
Unsupported use of the '=' operator. To compare values for equality, use '=='. To pass name-value arguments using the name=value format, provide these arguments after all other inputs. Thank you SO much.
% Loads the z, 32 bit, single channel image
rgbImage = imread('test1.jpg');
grayImage = double(rgbImage(:, :, 2));
%replace each pixel with the average of its 3x3 neighbors with
%filtering with a radius of 2 pixels
mean3=conv2(grayImage,[0 1 0; 1 1 1; 0 1 0]/5,'same');
imshow(mean3, []);
%set a pixel threshold cutoff in imagej it was 60 - minimize background by choosing a
%value cutoff, such that every pixel less than that value is considered one class,
%while every pixel greater than that value is considered the other class.
roi = grayImage < 60; % Define roi by thresholding
%convert the intensity values of the background to "nothing"
%rather than to 0 and keeps the other values
%divide this image by itself -> ROI
roifinal = roi./roi;
imshow(roifinal, []);
%Prompt user to load raw image
I = imread('raw.tif');
I = double(I);
%multiply ROI by the raw image
FinalRegOI = roi .* roi;
%Resulting region of Interest
imshow(FinalRegOI, []);
%inc the brightness of the image
I1 = I+50;
figure(1); imshow()
% Tabulate individual mean values
info_table = table(meanOfPixelsInRoi = mean(grayImage(roi)), meanOfPixelsInRoi, 'VariableNames', {'FileName', 'Mean of pixel blobs'});
finalcount = sum(meanOfPixelsInRoi)
disp(info_table)
  2 Comments
Star Strider
Star Strider on 31 Jul 2022
I suggest instead:
filename = 'test1.jpg';
rgbImage = imread(filename);
. . .
meanOfPixelsInRoi = mean(grayImage(roi));
info_table = table(filename, meanOfPixelsInRoi, 'VariableNames', {'FileName', 'Mean of pixel blobs'});
or something similar.
I suspect that there may be other problems, so I am not posting this as an answer.
Neo
Neo on 31 Jul 2022
Thank you for your response.
By the way, why do you suggest to use filename?
This is the error I got:
Error using table
All table variables must have the same number of rows.
Error in benzaanalysis (line 32)
info_table = table(grayImage, meanOfPixelsInRoi, 'VariableNames', {'FileName', 'Mean of pixel blobs'});

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 Jul 2022
info_table = table(meanOfPixelsInRoi = mean(grayImage(roi)), meanOfPixelsInRoi, 'VariableNames', {'FileName', 'Mean of pixel blobs'});
Until a couple of releases ago, that = in the middle of the table() call would have been strictly invalid syntax. I suspect that you are using one of those older versions.
In new enough versions, that call would be the equivalent of
table('meanOfPixelsInRoi', mean(grayImage(roi)), meanOfPixelsInRoi, 'VariableNames', {'FileName', 'Mean of pixel blobs'})
except possibly the = form would be invalid because there are positional parameters afterwards.
You cannot use = in the middle of a call to assign to a temporary variable. MATLAB is not C or C++. In C and C++ the result of an = is the rvalue and can be used in an expression, but assignment is syntactic in MATLAB and cannot be used inside expressions.
  3 Comments
Image Analyst
Image Analyst on 31 Jul 2022
You'd need to do
table(meanOfPixelsInRoi, mean(grayImage(roi)), meanOfPixelsInRoi, ...
'VariableNames', {'MeanOfPixelBlobs1', 'MeanOfPixelBlobs2', 'MeanOfPixelBlobs3'})
but why are you making a table wth only one row in it and all 3 columns the same??? Why not save them all up and make a table with the values from all your images.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!