how do save them all up and make a table with the values from all of my images?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2022 年 8 月 6 日
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.
採用された回答
Image Analyst
2022 年 8 月 4 日
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 件のコメント
Image Analyst
2022 年 8 月 11 日
編集済み: Image Analyst
2022 年 8 月 11 日
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!