why this code gives error?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2023-1-30
'auto' is not a valid option value for any parameter or any option value for imshow.
采纳的回答
Image Analyst
2023-1-30
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');
更多回答(1 个)
Sulaymon Eshkabilov
2023-1-29
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 个评论
Walter Roberson
2023-1-29
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!