%% Scale Display Range of Image
% Read a truecolor (RGB) image into the workspace. The data type of the image is uint8.

RGB = imread('peppers.png');

% Extract the green channel of the image. The green channel is the second color plane.

G = RGB(:,:,2);
imshow(G)

% Create a filter that detects horizontal edges in the image.

filt = [-1 -1 -1;0 0 0;1 1 1];

% Filter the green channel of the image using the filter2 function. The result is an image of data type double, with a minimum value of -422 and a maximum value of 656. Pixels with a large magnitude in the filtered image indicate strong edges.

edgeG = filter2(filt,G);

% Display the filtered image using imshow with the default display range. For images of data type double, the default display range is [0, 1]. The image appears black and white because the filtered pixel values exceed the range [0, 1].

imshow(edgeG)

% Display the filtered image and scale the display range to the pixel values in the image. The image displays with the full range of grayscale values.

imshow(edgeG,[])

% Copyright 2020 The MathWorks, Inc.