フィルターのクリア

How can I use a grayscale image as a input in this piece of code?

3 ビュー (過去 30 日間)
FS
FS 2017 年 8 月 3 日
コメント済み: Image Analyst 2017 年 8 月 4 日
function RedCellCount(dataImg)
data = imread(dataImg.Key{1});
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = imbinarize(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
fileName = dataImg.Key{1};
display(fileName)
display(length(stats));
I'm trying to load grayscale images in this piece of code from a folder whose path is in another .m file. This piece of code works perfectly fine for RGB images. but when i'm trying to use grayscale images its popping up with these errors:
>> RedCellCount
Not enough input arguments.
Error in RedCellCount (line 2)
data = imread(dataImg.Key{1});
and while using mapreduce() for grayscale images in another function, I got this error.
>> MAP must be a m x 3 array.
I've tried everything to make it run but the program is not accepting grayscale images as it is 1-D whereas RGB images are 3-D matrices.
I'm not able to understand why imread() is working for RGB images but not for grayscale images.
data = imread(dataImg.Key{1});
Any help will be highly appreciated. Thanks in advance.
  4 件のコメント
Geoff Hayes
Geoff Hayes 2017 年 8 月 4 日
FS - how about you show the full error message when your other function tries to pass the grayscale image into RedCellCount? If it is already an image (like you say) then you cannot pass it to RedCellCount since it is assuming that you are passing in a struct that has a filename. You will need to adapt the code to the new (grayscale image) input parameter.
Image Analyst
Image Analyst 2017 年 8 月 4 日
Before it crashes, put this on it's own line without a semicolon:
dataImg.Key{1}
What do you see in the command window? A string that contains a valid filename?

サインインしてコメントする。

回答 (1 件)

Julie Kraus
Julie Kraus 2017 年 8 月 3 日
You can make the grayscale image into an RGB image by using
NewImg=repmat(GreyImg,[1,1,3])
If you get an error due to the fact that it is using decimal points as opposed to intigers 1:256, before you run repmat
GreyImgNew=round(256*GreyImg)
  1 件のコメント
FS
FS 2017 年 8 月 4 日
Thanks for the suggestion. But how am I going to use it when
data = imread(dataImg.Key{1});
is not able to read grayscale images?. Can you please implement this function using your own logic for grayscale images?

サインインしてコメントする。

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by