Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Perform basic image segmentation using discrete quadratic models (DQM) and hybrid solvers.

License

NotificationsYou must be signed in to change notification settings

dwave-examples/image-segmentation

Repository files navigation

Open in GitHub CodespacesLinux/Mac/Windows build status

Image Segmentation

In this example, we show a basic image segmentation algorithm to partition animage into segments based on their pixel values. To solve this problem, we usethe hybrid discrete quadratic model solver available in Leap, and demonstratehow to build a DQM object from a set of numpy vectors.

Usage

To run the demo, type the command:

python image_segmentation.py

This will build a random image based on the specifications stated by the user.The first prompt will ask for the dimensions in pixels (a square image will becreated), and the second prompt will ask how many segments we want in our image.

Alternatively, the user can specify an input image such astest_2_segments.png by typing:

python image_segmentation.py test_2_segments.png

The program prompts the user for the number of segments to partition the imageinto.

After the program executes, a file is saved asoutput.png that shows theoriginal image on the left and the partition outlines in an image on the right.

A few example images have been provided.

  • test_2_segments.png is a small image with 2 segments.
  • test_4_segments.png is a small image with 4 segments.
  • test_image.jpeg is a larger image with 2 segments (foreground andbackground) that will take longer to run.

Note: For this demo to run relatively quickly, image sizes should be keptbelow 50x50 pixels with fewer than 10 segments. Several small image files areincluded in the repository.

Building the DQM

A simple method to partition an image into segments is to compare their pixelvalues. If colors are similar, then they might belong to the same object in theimage. This program builds a DQM object in which we have a variable for eachpixel and a case for each segment. As we compare pixels, we examine theirdifference using the providedweight function, which assigns smallervalues for more alike colors, and larger values for more different colors.Using this weight function, we assign quadratic biases between pixels in thesame cases. As the solver minimizes the energy landscape, it is then minimizingthe difference between pixels placed in the same segment or partition.

About

Perform basic image segmentation using discrete quadratic models (DQM) and hybrid solvers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp