Function Repository Resource:

ImageSaliencyCrop

Source Notebook

Crop an image while preserving the most salient contents

Contributed by: Jon McLoone

ResourceFunction["ImageSaliencyCrop"][img,a]

crops img to have an AspectRatio of a such that the result contains the most salient region of img.

ResourceFunction["ImageSaliencyCrop"][img]

crops img to have an AspectRatio of 1, such that the result contains the most salient region of img.

ResourceFunction["ImageSaliencyCrop"][img,{w,h}]

crops img to width w and height h, keeping the most salient region of img.

Details and Options

ResourceFunction["ImageSaliencyCrop"] has the following options:
MethodAutomaticchoose a method for determining saliency
"CentralityWeight"1priority for centering salient features
Possible settings for the Method option are:
"Itti"saliency based on color,intensity and orientation
"IttiColor"color map of the Itti algorithm
"IttiIntensity"intensity map of the Itti algorithm
"IttiOrientation"orientation map of the Itti algorithm
"HistogramContrast"saliency based on mean color difference to image pixels
"SpectralResidual"saliency based on the residual of the log spectrum
"ImageSignature"saliency based on foreground estimation
The Itti algorithm is based on human visual saliency. For all methods based on this algorithm, calculations are performed in the RGB color space.
For all Itti-based methods, different scales of the image are compared with each other. With Method{"method",{σ1,σ2,},{step1,step2,}}, scale σi is compared with coarser scales σi+stepj for all j. The default setting is {"Itti",{2,3,4},{3,4}}.

Examples

Basic Examples (1) 

Crop an image into a square aspect ratio, focusing on the salient contents:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/65da1b10-9ecc-462a-9618-c601c122c117"]
Out[1]=

Scope (2) 

Choose the target aspect ratio:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/9f3126cf-4990-4461-a9b3-edc1e031165b"]
Out[2]=

Choose the target image size:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/72f9763e-42b9-47a6-a4c1-bbbce83035e0"]
Out[3]=

Options (2) 

Method (1) 

ImageSaliencyCrop supports the Method options of ImageSaliencyFilter:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/7e8aa3b4-04a8-4b5f-a3c7-98d24509e27c"]
Out[4]=

CentralityWeight (1) 

"CentralityWeight" can be a value between -4 and 4. It changes the priority of placing the most salient features in the center of the image. If there are two salient points in the image, a high "CentralityWeight" will prefer to center on the most important. A low "CentralityWeight" will try to get both features in the output image:

In[5]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/71626b17-14d2-45d6-a334-7d952d67b627"]
Out[5]=
In[6]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/368424ed-5db7-4620-9869-5a2d5cb8b7ef"]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 14 January 2019

License Information