Main Content

정수 산술 연산

이 예제에서는 신호와 이미지를 나타내는 정수 데이터에 대해 산술 연산을 수행하는 방법을 보여줍니다.

정수 신호 데이터 불러오기

8비트 또는 16비트 A/D 변환을 사용하는 네 개의 계측기로부터 받은 신호의 측정 데이터셋을 불러옵니다. 데이터는 int8, int16, uint16으로 저장됩니다. 시간은 uint16으로 저장됩니다.

load integersignal

% Look at variables
whos Signal1 Signal2 Signal3 Signal4 Time1
  Name            Size            Bytes  Class     Attributes

  Signal1      7550x1              7550  int8                
  Signal2      7550x1              7550  int8                
  Signal3      7550x1             15100  int16               
  Signal4      7550x1             15100  uint16              
  Time1        7550x1             15100  uint16              

데이터 플로팅

먼저 두 개의 신호를 플로팅하여 신호 범위를 확인해 보겠습니다.

plot(Time1, Signal1, Time1, Signal2);
grid;
legend('Signal1','Signal2');

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Signal1, Signal2.

신호가 나타내는 실제 물리적 값(예: 전압)을 계산하기 위해, 이 값들은 스케일링해야 할 수도 있습니다.

데이터 처리

정수에 대해 +, -, *, / 같은 표준 산술 연산을 수행할 수 있습니다. Signal1과 Signal2의 합을 구하려 한다고 가정해 보겠습니다.

SumSig = Signal1 + Signal2; % Here we sum the integer signals.

이제 이 합을 플로팅하고 이 신호가 포화(Saturate)되는 위치를 확인해 보겠습니다.

cla;
plot(Time1, SumSig);
hold on
Saturated = (SumSig == intmin('int8')) | (SumSig == intmax('int8')); % Find where it has saturated
plot(Time1(Saturated),SumSig(Saturated),'rd')
grid
hold off

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers

위의 마커는 신호가 포화된 위치를 보여줍니다.

정수 이미지 데이터 불러오기

다음에는 일부 이미지 데이터에 대한 산술 연산을 살펴보겠습니다.

street1 = imread('street1.jpg'); % Load image data
street2 = imread('street2.jpg');
whos street1 street2
  Name           Size                Bytes  Class    Attributes

  street1      480x640x3            921600  uint8              
  street2      480x640x3            921600  uint8              

여기서 이미지는 24비트 색으로, uint8 데이터로 구성된 세 개의 평면으로 저장되어 있습니다.

이미지 표시

첫 번째 이미지를 표시합니다.

cla;
image(street1); % Display image
axis equal
axis off

Figure contains an axes object. The axes object contains an object of type image.

두 번째 이미지를 표시합니다.

image(street2); % Display image
axis equal
axis off

Figure contains an axes object. The axes object contains an object of type image.

이미지 스케일링

이미지를 정수로 저장된 상태로 유지하면서 배정밀도 상수로 이미지를 스케일링할 수 있습니다. 예를 들면 다음과 같습니다.

duller = 0.5 * street2; % Scale image with a double constant but create an integer
whos duller
  Name          Size                Bytes  Class    Attributes

  duller      480x640x3            921600  uint8              
subplot(1,2,1);
image(street2);
axis off equal tight
title('Original');  % Display image

subplot(1,2,2);
image(duller);
axis off equal tight
title('Duller');    % Display image

Figure contains 2 axes objects. Axes object 1 with title Original contains an object of type image. Axes object 2 with title Duller contains an object of type image.

이미지 추가

두 개의 거리 이미지를 더해서 흐릿하게 겹쳐 보이는 결과를 플로팅할 수 있습니다.

combined = street1 + duller; % Add |uint8| images
subplot(1,1,1)
cla;
image(combined); % Display image
title('Combined');
axis equal
axis off

Figure contains an axes object. The axes object with title Combined contains an object of type image.