showing error why?morphological hit and miss operation
1 view (last 30 days)
Show older comments
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);
Answers (2)
Walter Roberson
on 14 Nov 2016
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.)
1 Comment
Torkan
on 14 Oct 2019
So, Walter,
Even if we change the format of the file, this is not going to work right?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!