Use PhotoShop and Matlab to test Shape Context Matching

Source: Internet
Author: User

 

Abstract

Matlab has a strong IP address, which provides powerful functions for the image at the algorithm level, but it is not good enough for image interaction.

It is best to be able to draw test images in PhotoShop, and then design algorithms in Matlab to test.

This article briefly introduces how to combine these two things.

This
Times
The purpose of the test is to achieve: draw two images in ps and use shape context to match the two images.

 

PhotoShop actually provides a GUI. Of course, the PS function is very powerful, and the PS script can also implement a very powerful processing function.

For the Shape Context code, see [1].
.

1/Configuration

My testing environment is: PhotoShop CS3 Extended + MATLAB R2009a.

After installing PS CS3, the installation directory contains a Matlab directory:

This is the directory of Photoshop Toolbox for MATLAB.

Configuration method: add the directory to the Path sequence in Matlab, and refresh the toolbox.


After the configuration is complete, you can see the help items of PhotoShop toolbox in the help of Matlab.


The Matlab directory contains some basic ps interaction functions. These functions are essentially an encapsulation of PS scripts.

For example, psblur. m:

Function [] = psblur () <br/> % PSBLUR Run the Blur filter. <br/> % Example: <br/> % psblur () <br/> % Build up the JavaScript <br/> pstext = ['var B = "";'... <br/> 'try {'... <br/> 'app. activeDocument. activeLayer. applyBlur ();'... <br/> 'B = "OK ";'... <br/> '}'... <br/> 'catch (e ){'... <br/> 'B = e. toString ();'... <br/> '}'... <br/> 'B;']; <br/> psresult = psjavascriptu (pstext); <br/> if ~ Strcmp (psresult, 'OK') <br/> error (psresult); <br/> end <br/>

Use pstext to build a script to call the command, and then use psjavascriptu to call the javascript script as a parameter. Therefore, in view of the powerful PS script, we can achieve full control of ps in matlab.

2/several commands used

Pslaunch-open ps (you can also open it with the mouse)

Psconfig-configure image operation attributes

Psnewdoc-create an image in ps

Psdocnames-Get all open file names in ps

Pssetactivedoc-set activity files

Psgetpixels-retrieve image pixels from ps


These commands are basically used, which is very simple. Here, ps is just used as an input GUI.

3/Test Procedure

The purpose of this test is to achieve: draw two images in ps and use shape context to match the two images.


First, set the basic unit to pixel. Then, open ps in Matlab and create two 64x64 images.

Pslaunch; <br/> psconfig ('pixels', 'pixels'); <br/> psnewdoc (64,64); <br/> psnewdoc (64,64 );

Drawing in ps, here I drew two simple outlines:

Then, obtain the data of the two images in matlab:

Docs = psdocnames (); <br/> pssetactivedoc (docs {1}); <br/> im1 = psgetpixels (); <br/> pssetactivedoc (docs {2 }); <br/> im2 = psgetpixels ();

I wrote an m file to detect the contour of the image and sample the contour.

Function samp = select_sample_points (image, N) <br/> % select N sample points from a contour and draw these points on the contour <br/> % Input: <br/> % filename-image file <br/> % N-number of sample points <br/> % Output: <br/> % samp-Nx2 matrix <br/> % by visionfans, 26/3/2011 <br/> if ischar (image) <br/> BW = imread (filename); <br/> else <br/> BW = image; <br/> end <br/> if ~ Islogical (BW) <br/> BW = im2bw (BW); <br/> end <br/> [rows, cols] = size (BW ); <br/> % select sample points from contour <br/> boundaries = bwboundaries (BW, 'noholes '); <br/> bd = boundaries {1 }; <br/> sel = floor (linspace (1, size (bd, 1)-size (bd, 1)/N, N )); <br/> samp = bd (sel, :); </p> <p> % view sample points <br/> % figure; imshow (BW ); <br/> % hold on; <br/> % plot (samp (:, 2), samp (:, 1), 'ro '); <br/> % hold off; </p> <p> % normalize sample points <br/> samp = samp. /max (rows, cols); <br/>

Then, you can directly use Shape Context [1].
.

4/result

PS:

For more information, see [1
, 2
, 3
, 4
, 5
, 6
].

Referrences


[1] Matching with Shape Contexts, http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/ SC _digits.html


[2] Photoshop CS3 * Set up MATLAB and Photoshop (Photoshop Extended), http://livedocs.adobe.com/en_US/Photoshop/10.0/WS62AB0C24-121F-401c-9097-ABCE350A075B.html


[3] Photoshop + MATLAB, http://www.mit.edu /~ Kimo/blog/psmat.html


[4] John Nack on Adobe: Photoshop + Matlab = Art, http://blogs.adobe.com/jnack/2007/06/photoshopmatlabart.html


[5]
MATLAB
Photoshop self-reported file Inventory (PS installation directory/Matlab)


[6] Adobe Photoshop CS3 Extended + MATLAB 7.0 +, http://www.inthemod.com/bps? P = 136


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.