Skip to main content

Example on Images

Drag and drop your favourite image to a cell

Download original notebook
Import[FileNameJoin[{"attachments", "tstballs-d08.png"}]];
img = ImageResize[%, 450]

You can work with it if it was a symbol

(*VB[*)(FrontEndRef["0b6d8698-67ea-4a7c-a54d-65c5c3b6b7eb"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKGySZpViYWVrompmnJuqaJJon6yaamqTompkmmyYbJ5klmacmAQCFwBYP"*)(*]VB*) // ColorNegate
(*VB[*)(FrontEndRef["171e4eff-b508-40c5-b407-588c0e623f70"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKG5obppqkpqXpJpkaWOiaGCSb6iaZGJjrmlpYJBukmhkZp5kbAACB1BVD"*)(*]VB*)

And perform mathematical operations

(*VB[*)(FrontEndRef["0b6d8698-67ea-4a7c-a54d-65c5c3b6b7eb"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKGySZpViYWVrompmnJuqaJJon6yaamqTompkmmyYbJ5klmacmAQCFwBYP"*)(*]VB*) - EdgeDetect[(*VB[*)(FrontEndRef["0b6d8698-67ea-4a7c-a54d-65c5c3b6b7eb"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKGySZpViYWVrompmnJuqaJJon6yaamqTompkmmyYbJ5klmacmAQCFwBYP"*)(*]VB*)]
(*VB[*)(FrontEndRef["4b53ab2e-a868-4a4b-ab8f-6af6d1b87a6d"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKmySZGicmGaXqJlqYWeiaJJok6SYmWaTpmiWmmaUYJlmYJ5qlAACPKhZi"*)(*]VB*)

Features detection

(*VB[*)(FrontEndRef["61cd9b03-0523-46b3-938e-c58fc3742f3b"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKmxkmp1gmGRjrGpgaGeuamCUZ61oaW6TqJptapCUbm5sYpRknAQB53hVF"*)(*]VB*);

Image[%, "ImageResolution"->Automatic];
HighlightImage[%, {Yellow, ImageCorners[%, 1, .001, 5]}, ImageSize->300]
(*VB[*)(FrontEndRef["65c3fc01-f74c-4d04-a35c-018c20279cd5"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKm5kmG6clGxjqppmbJOuapBiY6CYamybrGhhaJBsZGJlbJqeYAgCCdxVm"*)(*]VB*)

Machine learning

Using local neural networks one can perform classification

(*VB[*)(FrontEndRef["0b6d8698-67ea-4a7c-a54d-65c5c3b6b7eb"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKGySZpViYWVrompmnJuqaJJon6yaamqTompkmmyYbJ5klmacmAQCFwBYP"*)(*]VB*);

ImageCases[%, AcceptanceThreshold->0.1]
<|(*VB[*)(Entity["Concept", "Ball::qs4s5"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KWlMIB4nkHDNK8ksqXTKrwhmB/Kc8/OSUwtKgkHqkhJzcgBmZw1M"*)(*]VB*)->{(*VB[*)(FrontEndRef["4374ee85-95fe-4329-b5ce-2d5f9174673d"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKmxibm6SmWpjqWpqmpeqaGBtZ6iaZJqfqGqWYplkampuYmRunAAB/JRVg"*)(*]VB*),(*VB[*)(FrontEndRef["d850a4a3-a2eb-4702-904d-2d5ba8d82fc2"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKp1iYGiSaJBrrJhqlJumamBsY6VoamKToGqWYJiVapFgYpSUbAQCEYxXE"*)(*]VB*),(*VB[*)(FrontEndRef["78af6e67-4fea-428b-a503-31c2b4e1572c"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKm1skppmlmpnrmqSlJuqaGFkk6SaaGhjrGhsmGyWZpBqamhslAwCIMBWg"*)(*]VB*)},(*VB[*)(Entity["Concept", "DiningTable::6ypqf"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KWlMIB4nkHDNK8ksqXTKrwhmB/Kc8/OSUwtKgnmA7JTMvMy8dIWSxKScVADe3BBa"*)(*]VB*)->{(*VB[*)(FrontEndRef["d82156d2-e22a-411d-b955-9ca4c771f8e5"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKp1gYGZqapRjpphoZJeqaGBqm6CZZmprqWiYnmiSbmxumWaSaAgB+DBV3"*)(*]VB*)}|>

And then highlight it on image

HighlightImage[img, {AbsolutePointSize[20], 
  ImagePosition[#, (*VB[*)(Entity["Concept", "Ball::qs4s5"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KWlMIB4nkHDNK8ksqXTKrwhmB/Kc8/OSUwtKgkHqkhJzcgBmZw1M"*)(*]VB*), AcceptanceThreshold->0.1] &}]
(*VB[*)(FrontEndRef["2dec5015-5425-40c2-bd10-6da41aba8b27"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKG6WkJpsaGJrqmpoYmeqaGCQb6SalGBromqUkmhgmJiVaJBmZAwB+AxWD"*)(*]VB*)

Generating images

Image can be used as a costructor as well

Image[((*GB[*){{1(*|*),(*|*)0(*|*),(*|*)0(*|*),(*|*)0.5}(*||*),(*||*){0(*|*),(*|*)1(*|*),(*|*)0(*|*),(*|*)0}(*||*),(*||*){0(*|*),(*|*)0(*|*),(*|*)1(*|*),(*|*)0}(*||*),(*||*){0.5(*|*),(*|*)0(*|*),(*|*)0(*|*),(*|*)1}}(*]GB*)), Magnification->50]
(*VB[*)(FrontEndRef["5221572e-3894-433b-b7ba-d99246f0e35c"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKmxoZGZqaG6XqGltYmuiaGBsn6SaZJyXqplhaGpmYpRmkGpsmAwBxcRUY"*)(*]VB*)
Image[RandomReal[1, {4, 5, 3}], Magnification->50]
(*VB[*)(FrontEndRef["d6bf6ca5-24f8-4950-b24c-39956e15011e"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKp5glpZklJ5rqGpmkWeiaWJoa6CYZmSTrGltampqlGpoaGBqmAgCGwxVH"*)(*]VB*)

Using cellular automaton

Image[CellularAutomaton[30, {{1}, 0}, 40], "Bit", Magnification -> 5]
(*VB[*)(FrontEndRef["9d2d5620-6f75-4ad2-9160-3a79b8c69342"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKW6YYpZiaGRnomqWZm+qaJKYY6VoamhnoGieaWyZZJJtZGpsYAQB6GhTv"*)(*]VB*)

Create image from a reigon

RegionImage[Annulus[], RasterSize->150]
(*VB[*)(FrontEndRef["3bfcf8c0-0daf-4a39-9e5c-2a722275e817"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKGyelJadZJBvoGqQkpumaJBpb6lqmmibrGiWaGxkZmZumWhiaAwCUIxXV"*)(*]VB*)

Create linear gradient and combine it with a previous image

(*FB[*)((LinearGradientImage[{{Left, Bottom}, {Right, Top}} -> "Rainbow", {150, 150}] + %)(*,*)/(*,*)(2))(*]FB*)
(*VB[*)(FrontEndRef["ac9b0524-074a-41c2-b552-7baffc67ec1f"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKJyZbJhmYGpnoGpibJOqaGCYb6SaZmhrpmiclpqUlm5mnJhumAQCCjRX2"*)(*]VB*)

Rasterization of WL expressions (experimental)

Rasterize[Plot[x, {x,0,1}, ImageSize->250]]
(*VB[*)(FrontEndRef["c889f25a-6126-48fb-a11f-6f40eb445fcc"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKJ1tYWKYZmSbqmhkamemaWKQl6SYaGqbpmqWZGKQmmZiYpiUnAwCBzRXZ"*)(*]VB*)

Or expression

Rasterize[x+y]
(*VB[*)(FrontEndRef["656edba5-d2b5-4881-8f2b-32da1c97c7f6"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKm5mapaYkJZrqphglmeqaWFgY6lqkGSXpGhulJBomW5onm6eZAQCIxBXd"*)(*]VB*)