%% Visualize Which Parts of an Image are Important for Classification
% Use imageLIME to visualize the parts of an image are important to a network for a classification decision.
% Import the pretrained network SqueezeNet.

net = squeezenet;

% Import the image and resize to match the input size for the network.

X = imread("laika_grass.jpg");
inputSize = net.Layers(1).InputSize(1:2);
X = imresize(X,inputSize);

% Display the image. The image is of a dog named Laika.

imshow(X)

% Classify the image to get the class label.

label = classify(net,X)

% Use imageLIME to determine which parts of the image are important to the classification result.

scoreMap = imageLIME(net,X,label);

% Plot the result over the original image with transparency to see which areas of the image affect the classification score.

figure
imshow(X)
hold on
imagesc(scoreMap,'AlphaData',0.5)
colormap jet

% The network focuses predominantly on Laika's head and back to make the classification decision. Laika's eye and ear are also important to the classification result.
% Copyright 2020 The MathWorks, Inc.