how do save them all up and make a table with the values from all of my images?

2 visualizaciones (últimos 30 días)
my code has a table wth only one row in it and all 3 columns the same??? How do I save them all up and make a table with the values from all my images? Thank you!
i also have an error:
Unrecognized function or variable 'meanOfPixelsInRoi'.
Error in line 32
info_table = table(meanOfPixelsInRoi, mean(grayImage(roi)), meanOfPixelsInRoi,'VariableNames', {'MeanOfPixelBlobs1', 'MeanOfPixelBlobs2', 'MeanOfPixelBlobs3'})
% 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, []);
% Tabulate individual mean values
meanOfPixelsInRoi = mean(grayImage(roi));
info_table = table(meanOfPixelsInRoi, mean(grayImage(roi)), meanOfPixelsInRoi,'VariableNames', {'MeanOfPixelBlobs1', 'MeanOfPixelBlobs2', 'MeanOfPixelBlobs3'})
finalcount = sum(meanOfPixelsInRoi)
disp(info_table)
  7 comentarios
Neo
Neo el 6 de Ag. de 2022
Thank you both @image analyst and @walter Robertson
Image Analyst
Image Analyst el 6 de Ag. de 2022
See this snippet and adapt as needed.
% Plot the borders of all the blobs in the overlay above the original grayscale image
% using the coordinates returned by bwboundaries().
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
imshow(originalImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(mask);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
fontSize = 15;
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Ag. de 2022
You need to get all your filenames in a cell array (see the FAQ)
Then
You'd need to do something like this inside your loop over k:
for k = 1 : numImages
% Loads the z, 32 bit, single channel image
rgbImage = imread(allFileNames{k});
if size(rgbImage, 3) > 1
% Take green channel.
grayImage = double(rgbImage(:, :, 2));
else
% It's already gray scale.
grayImage = double(rgbImage);
end
%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, []);
drawnow; % Force it to repaint NOW.
%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
% The next line is not needed at all.
roifinal = roi./roi; % What the heck? This will give just an image of 1s and nans.
imshow(roifinal, []);
% Tabulate individual mean values
meanOfPixelsInRoi(k) = mean(grayImage(roi));
end % of loop over k for all images.
% Then after the loop over all images, create your table
info_table = table(allFileNames, meanOfPixelsInRoi(:), 'VariableNames', {'FileName', 'Mean of pixel blobs'});
finalcount = sum(meanOfPixelsInRoi)
disp(info_table)
Make sure allFileNames is a column vector where the filenames are listed vertically. To make sure you can do this
allFileNames = reshape(allFileNames, [], 1);
  27 comentarios
Neo
Neo el 11 de Ag. de 2022
My apologizes you are quite right. Your code does indeed do what I want as well. Thank you.
what I meant by my sentences was that if you look at the min values for tiffex2 you will see that all of the mins are 60 but in tifexfinal (where I have done additional steps) you will see that the mins are less than 60 and various.
I only want analyze the red blobs as your code does, but I did not know if stopping at the tiffex2 step (only thresholding no dividing or nans) would restrict the mean and area values (i dont know, does it?). I suppose it may since we see a difference in the numerical value of the min in tiffex2 vs tiffexfinal min but the means are the same so maybe it doesnt.
I noticed that your code does not produce the individual tabulated mean values of the blobs. Why is that?
Image Analyst
Image Analyst el 11 de Ag. de 2022
Editada: Image Analyst el 11 de Ag. de 2022
Well, tiffex2 is created in your code, not mine, and like I said, I don't think it's necessary.
If you want the data to come back as a table, pass in 'table' as the first argument to regionprops(). I usually get the results back as a structure array because that's the way they've done it historically and I'm used to that way. To get back as table
props = regionprops('table', mask, grayImage);
To get back as a structure array
props = regionprops(mask, grayImage);
% To get areas in an array from the structure array
allAreas = [props.Area]
If it's doing what you want now, then please click the "Accept this answer" link. Thanks in advance.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by