1

このコードセクションでエラーが発生しています

 X=imread ('Lighthouse.jpg'); %reads picture as int8 matrix  
figure, imagesc(X), colormap gray, title('original picture'), % display picture  
filter=[-1 0 1; -2 0 2; -1 0 1]; % builds Sobel filter matrix  
filter=single(filter); %convert double to single 
x=single(X); % convert int8 to single  
x=x/max(max(x)); %normalisation to [0,1] 

私が得るエラー:

Error using  / 
Inputs must be 2-D, or at least one input must be scalar.
To compute elementwise RDIVIDE, use RDIVIDE (./) instead.
Error in sobel (line 10)
x=x/max(max(x)); %normalisation to [0,1]

また、./提案どおりに使用すると、新しいエラーが発生します。

Array dimensions must match for binary array op.
Error in sobel (line 10)
x=x./max(max(x)); %normalisation to [0,1]

正規化のステップで何か間違ったことをしています。

この問題を解決するにはどうすればよいですか?

4

3 に答える 3

2

カドゥケウスの答えは正しいですが。3 色すべてを一度に正規化します。あなたのケースにとっておそらくより良いのはrgb2gray、単一のカラーチャネルを取得し、代わりにそれを正規化することです(を使用x/max(x(:)))。

X=imread ('lighthouse.png'); %reads picture as int8 matrix  
filter=[-1 0 1; -2 0 2; -1 0 1]; % builds Sobel filter matrix  
filter=single(filter); %convert double to single 
x = single(rgb2gray(X)); % rgb2gray gives a uint8, you want single
% x=x/max(x(:)); %normalisation to [0,1] , not needed here as x can directly be used
% for Sobel purposes as it's a grey scale image.

figure;
subplot(1,2,1)
imagesc(X)
colormap(gray)
title('original picture'), % display picture 
subplot(1,2,2)
imagesc(x)
colormap(gray)
title 'Grey scale'

ここに画像の説明を入力


最初のエラーの理由はmax、列方向の最大値を与えることと、これが 3D 行列であることです。max(max())したがって、目的のスカラーではなく、1D が得られます。

max(max())次に、完全な行列と同じ量のエントリを持たない配列を与えるため、2 番目のエラーが発生します (明らかに)。

基本的に if size(x) = [row, column channels]size(max(x)) = [row channels] およびsize(max(max(x)) = [row]. コロン演算子を使用すると、実際には 3D マトリックス全体が 1 つの列ベクトルになり、max(x(:))すべての行、列、およびチャネルの最大値である 1 つの値が得られます。

于 2018-05-07T08:29:28.523 に答える