why this code gives error?
3 views (last 30 days)
Show older comments
color=imread('C:\Users\User\Desktop\matlab\photo.png');
gray=rgb2gray(color);
gray=double(gray);
pfs=fspecial('gaussian',[5 5],2);
motion_filter=fspecial('motion',10,45);
convolution_with_gaussian_filter=conv2(gray,pfs);
convolution_with_motion_filter=imfilter(gray,motion_filter);
self_convolution=conv2(gray,gray);
subplot(2,2,1),imshow(color);
subplot(2,2,2),imshow(convolution_with_gaussian_filter,'auto');title('1')
subplot(2,2,3),imshow(convolution_with_motion_filter,'auto');
subplot(2,2,4),imshow(self_convolution,'auto');
This is the error message:
Error using images.internal.imageDisplayParsePVPairs (line 72)
The parameter, auto, is not recognized by imageDisplayParsePVPairs
Error in images.internal.imageDisplayParseInputs (line 70)
[common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in Untitled3 (line 10)
subplot(2,2,2),imshow(convolution_with_gaussian_filter,'auto');title('1')
3 Comments
Walter Roberson
on 30 Jan 2023
'auto' is not a valid option value for any parameter or any option value for imshow.
Accepted Answer
Image Analyst
on 30 Jan 2023
Try using [] instead of 'auto':
color=imread('peppers.png');
grayImage=rgb2gray(color);
grayImage=double(grayImage);
pfs=fspecial('gaussian',[5 5],2);
motion_filter=fspecial('motion',10,45);
convolution_with_gaussian_filter=conv2(grayImage,pfs);
convolution_with_motion_filter=imfilter(grayImage,motion_filter);
self_convolution=conv2(grayImage,grayImage, 'full'); % Will be twice as big in each dimension.
subplot(2,2,1),imshow(color); axis('on', 'image');
subplot(2,2,2),imshow(convolution_with_gaussian_filter,[]); title('1'); axis('on', 'image');
subplot(2,2,3),imshow(convolution_with_motion_filter,[]); axis('on', 'image');
subplot(2,2,4),imshow(self_convolution,[]); axis('on', 'image');
More Answers (1)
Sulaymon Eshkabilov
on 29 Jan 2023
Here is the corrected code:
[color, I_map]=imread('C:\Users\User\Desktop\matlab\photo.png');
gray=rgb2gray(color);
gray=double(gray);
pfs=fspecial('gaussian',[5 5],2);
motion_filter=fspecial('motion',10,45);
convolution_with_gaussian_filter=conv2(gray,pfs);
convolution_with_motion_filter=imfilter(gray,motion_filter);
self_convolution=conv2(gray,gray);
subplot(2,2,1),imshow(color,I_map);
subplot(2,2,2),imshow(convolution_with_gaussian_filter,I_map);title('1')
subplot(2,2,3),imshow(convolution_with_motion_filter,I_map);
subplot(2,2,4),imshow(self_convolution, I_map);
2 Comments
Walter Roberson
on 29 Jan 2023
The second output of imread is the colormap for the case that the image is an indexed image (which includes the case of GIF). In the case of non-indexed images the second output is empty.
If the image was indexed then the first output of imread would be 2d and in that case rgb2gray would be invalid.
If the image was grayscale without a map then the first output of imread would be 2d and rgb2gray would be invalid.
If the image was rgb truecolor then the first output of imread would be 3d and rgb2gray would succeed, but the second output would be empty.
That empty second output is tgen carried down to the imshow calls in the code, and becomes an empty second input to imshow. An empty second input to imshow is not interpreted as an empty colormap: it is interpreted as an empty scaling range, so the imshow would act similar to imagesc in rescaling the data so that the colormap covered the data range instead of the range implied by the data type.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!