counting pixels within an image file
2 ビュー (過去 30 日間)
古いコメントを表示
I have an image and I'm trying to count the number of white and non white pixels of an image. The original image is 16-bit TIF but I converted to 8-bit JPG so I could upload the file.
The code I'm using is below. I'm just a few days with using MATLAB and I'm having issues getting just this simple piece of code working. I get errors starting on line 3
originalImageX = imread('10mgml.tif');
originalImage = rgb2gray(originalImageX);
imagedetails = ifinfo;
display (imagedetails)
binaryImage = originalImage ;
binaryImage = imfill(binaryImage, 'holes');
labeledImage = bwlabel(binaryImage, 8);
blobMeasurements = regionprops(labeledImage, originalImage, 'EulerNumber');
numberOfBlobs = size(blobMeasurements, 1);
The errors that I'm getting.
Error using rgb2gray>parse_inputs (line 80)
MAP must be a m x 3 array.
Error in rgb2gray (line 52)
isRGB = parse_inputs(X);
Error in TestscriptforMatt (line 3)
originalImage = rgb2gray(originalImageX);
Thanks for the help everyone.
0 件のコメント
採用された回答
Guillaume
2017 年 6 月 5 日
Most likely, your image is already greyscale. What is
size(originalImageX)
?
2 件のコメント
その他の回答 (1 件)
Image Analyst
2017 年 6 月 5 日
originalImageX is already gray scale. Don't call regb2gray() automatically. Do this:
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
This calls it only if it's a color image and should avoid the error.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!