why this code gives error?

3 Ansichten (letzte 30 Tage)
waruna
waruna am 29 Jan. 2023
Kommentiert: waruna am 1 Feb. 2023
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 Kommentare
waruna
waruna am 30 Jan. 2023
Sir 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')
Walter Roberson
Walter Roberson am 30 Jan. 2023
'auto' is not a valid option value for any parameter or any option value for imshow.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 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');

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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 Kommentare
Walter Roberson
Walter Roberson am 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.
waruna
waruna am 1 Feb. 2023
thankyou

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by