showing error why?morphological hit and miss operation

4 次查看(过去 30 天)
clc;
clear all;
close all;
bw=imread('hm.png');%reading image 1
figure;
imshow(bw);title('Original Image1 of dilation');%displaying original image
se1=strel([0 0 0;0 1 1;0 1 0]);
se2=strel([1 1 1;1 0 0;1 0 0]);
bw2=bwhitmiss(bw,se1,se2);
figure;
imshow(bw2);
title('after hit and miss operation');%displaying original image 2
error is.........
Error using imageDisplayValidateParams>validateCData (line 121)
If input is logical (binary), it must be two-dimensional.
Error in imageDisplayValidateParams (line 31)
common_args.CData = validateCData(common_args.CData,image_type);
Error in imageDisplayParseInputs (line 79)
common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 198)
[common_args,specific_args] = ...
Error in hitmiss3 (line 11)
imshow(bw2);

回答(2 个)

Matt J
Matt J 2012-10-20
Your bw is not class logical. Check "class(bw)" or "whos bw"

Walter Roberson
Walter Roberson 2016-11-14
You have
bw=imread('hm.png');%reading image 1
and that is reading in an RGB image, which is a numeric array of dimension 3. That is supported by bwhitmiss, creating a binary (logical) 3D array.
imshow() does not know how to display 3D arrays of class logical.
If you want to use the binary values as indicating that the respective color channel is fully on or fully off, then
imshow( double(bw2) )
If you had thought the image was not RGB, then keep in mind that RGB images can look gray. png files are typically RGB, but sometimes are grayscale.
(jpg files on the other hand, are rarely stored as grayscale in my experience; I have only encountered perhaps two such files. So a jpg file is very likely an RGB file even if the image looks gray.)

Community Treasure Hunt

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

Start Hunting!

Translated by