You are hereFeed aggregator

Feed aggregator


Getting the math right

Matlab Image processing blog - 2016, September 16 - 10:54

Because I work regularly with developers on the MATLAB Math team, I see the questions that come to them from tech support. Today there was an interesting one.

A user observed that computing the sin function takes longer for very big numbers. The user asked, "Why is that?"

Well, first let's see if we can reproduce the observation. Start by making a vector with one million numbers in the interval [0,1].

rng(42) x = rand(1000000,1);

(I seeded the random number generator using rng so that the numbers below don't change each time I run this script.)

How long does it take to compute the sin of all those numbers?

f = @() sin(x); timeit(f) ans = 0.002102730998500

Now repeat the timing experiment with another vector containing one million numbers in the interval [100000000,100000000+1].

x2 = x + 100000000; g = @() sin(x2); timeit(g) ans = 0.027343141998500

The user is right, it does take longer!

Here's the straightforward explanation: For large numbers, it takes more computation to produce an accurate result.

To illustrate, let's look at the output of sin for one large number in MATLAB and compare it the result from another application. I'm going to use Excel for this comparison, but the results will be similar for code you write in C that calls the standard C math library function, sin().

z = x2(1) z = 1.000000003745401e+08 matlab_result = sin(z) matlab_result = 0.734111589042897 excel_result = 0.734111669990523 excel_result = 0.734111669990523

These two results agree to only 6 digits!

Let's use the Symbolic Math Toolbox to compute sin(z) with 20 decimal digits of accuracy.

sym_result = sin(sym(z)) sym_result = sin(3355443212567481/33554432) vpa(sym_result,20) ans = 0.73411158904289725019

From this calculation, you can see that the MATLAB result is accurate to 15 decimal digits, whereas the Excel result is accurate to only 6 digits.

That's called sweating the details.

\n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016b

. ##### SOURCE END ##### 0780227fb97d40c488b0f8999338a84e -->

Categories: Blogs

Ten years of MATLAB blogging

Matlab Image processing blog - 2016, September 12 - 10:23

As I mentioned last time, MATLAB Central is celebrating its 15th anniversary. You should head on over there to try one of the two contests, the Scavenger Hunt and the Triathlon. Or compete in both!

This year also marks my tenth year of blogging. I still remember in 2005 when my friend Ned Gulley asked me, “Hey Steve, what do you think about writing a blog for MATLAB Central?” Two thoughts passed immediately through my head.

  • That sounds like a really interesting opportunity, and it would be a nice way to push beyond my comfort zone.
  • If you do your usual thing of analyzing and pondering Ned’s question for a few days, you’re going to get cold feet.

So I just said, “Sure, I’ll do it!” A few months later, in January 2006, a little bit after Loren started her Art of MATLAB blog, I made my first post.

That first year, I posted about algorithms (such as polygon scan conversion), signal processing concepts (such as separable convolution), Image Processing Toolbox tips and tricks (such as labeling labeled objects), and MATLAB in general (such as my series on how MATLAB image display works).

And that’s pretty much the way it’s worked ever since.

I recall that it took me almost four years to get up the nerve to start posting about Fourier transform concepts. It is such a misunderstood area, and people with different technical backgrounds learn the concepts in different orders and with different terms. But I finally dipped my toes in those waters in November 2009, and now there are 21 posts in the Fourier transforms category.

I’ll leave you with pointers to two other memorable posts. First, just before a summer holiday weekend in 2007, I invited readers to post their favorite uses and abuses of image processing in the movies. I loved the comment thread that resulted.

The other was in October 2006, when I broke my nine-year silence to explain the story behind the default MATLAB image.

That’s it for this post - my 500th!

Categories: Blogs

If DRM is so great, why won’t anyone warn you when you’re buying it?

Cory Doctorow - 2016, September 8 - 09:12

Last month, I filed comments with the Federal Trade Commission on behalf of Electronic Frontier Foundation, 22 of EFF’s supporters, and a diverse coalition of rightsholders, public interest groups, and retailers, documenting the ways that ordinary Americans come to harm when they buy products without realizing that these goods have been encumbered with DRM, and asking the FTC to investigate fair labeling for products that come with sneaky technological shackles.


In my latest Guardian column, DRM products are defective by design. Time to tell users what they’re buying, I describe the process by which we came to file, and what we’re hoping will come of it.

In our open letter on DRM labelling – a letter signed by a diverse coalition of rights holders, public interest groups, and publishers – we ask the FTC to take action to ensure that people know what they’re getting when they buy products encumbered with DRM. DRM-free publishers love this idea, because where DRM-labelling prevails, customers overwhelmingly favour DRM-free products.

But DRM-encumbered publishers should also love this, because they keep telling us that people don’t mind DRM. One significant challenge to DRM labelling is that the restrictions imposed by DRM can be incredibly complex – a video may play back on most manufacturers’ displays, but not all, and not at every resolution, and not if the video player believes that it is running in a virtual machine or has been relocated to a different country.

What’s more, most modern DRM is designed for “renewability” – which is a DRM-vendor euphemism for a remote kill-switch. These DRM tools phone home periodically for updates, and install these updates without user intervention, and then disable some or all of the features that were there when you bought the product.


DRM products are defective by design. Time to tell users what they’re buying
[The Guardian]

Categories: Blogs

The privacy wars have been a disaster and they’re about to get a LOT worse

Cory Doctorow - 2016, September 6 - 10:57



In my latest Locus column, The Privacy Wars Are About to Get A Whole Lot Worse, I describe the history of the privacy wars to date, and the way that the fiction of “notice and consent” has provided cover for a reckless, deadly form of viral surveillance capitalism.

As bad as things have been, they’re about to get much, much worse: the burgeoning realm of the “Internet of Things” is filled with surveillance devices that you can’t even pretend to give your consent to.

It’s possible that we can prevent the proliferation of reckless overcollection and retention of data, maybe by the eventual success of a few ambitious class-action lawyers, but that will only happen if we stop the accompanying plague of “binding arbitration,” which takes away your right to seek justice for corporate malfeasance.

You will ‘‘interact’’ with hundreds, then thou­sands, then tens of thousands of computers every day. The vast majority of these interactions will be glancing, momentary, and with computers that have no way of displaying terms of service, much less presenting you with a button to click to give your ‘‘consent’’ to them. Every TV in the sportsbar where you go for a drink will have cameras and mics and will capture your image and process it through facial-recognition software and capture your speech and pass it back to a server for continu­ous speech recognition (to check whether you’re giving it a voice command). Every car that drives past you will have cameras that record your like­ness and gait, that harvest the unique identifiers of your Bluetooth and other short-range radio devices, and send them to the cloud, where they’ll be merged and aggregated with other data from other sources.

In theory, if notice-and-consent was anything more than a polite fiction, none of this would hap­pen. If notice-and-consent are necessary to make data-collection legal, then without notice-and-consent, the collection is illegal.

But that’s not the realpolitik of this stuff: the reality is that when every car has more sensors than a Google Streetview car, when every TV comes with a camera to let you control it with gestures, when every medical implant collects telemetry that is collected by a ‘‘services’’ business and sold to insurers and pharma companies, the argument will go, ‘‘All this stuff is both good and necessary – you can’t hold back progress!’’

It’s true that we can’t have self-driving cars that don’t look hard at their surroundings all the time, and pay especially close attention to humans to make sure that they’re not killing them. However, there’s nothing intrinsic to self-driving cars that says that the data they gather needs to be retained or further processed. Remember that for many years, the server logs that recorded all your inter­actions with the web were flushed as a matter of course, because no one could figure out what they were good for, apart from debugging problems when they occurred.

The Privacy Wars Are About to Get A Whole Lot Worse [Locus Magazine]

Categories: Blogs

The MATLAB community and me

Matlab Image processing blog - 2016, August 29 - 08:44

As Ned Gulley posted over on the MATLAB Community blog last week, MATLAB Central is 15 years old.

Ned commented that MATLAB Central was “giving a modern web-based home to a community that was already thriving.” That reminded me of how important MathWorks participation in that community has been to me personally.

Many, many moons ago, as the calendar changed and 1992 became 1993, I was a fairly unhappy electrical engineering professor. I was thinking about changing my career path, but I didn’t have any solid ideas about what to do outside academia.

I was a heavy MATLAB user, so I immediately subscribed when the new Usenet group, comp.soft-sys.matlab, launched in January. I soon noticed when Cleve Moler, creator of the original MATLAB, posted a note from MathWorks:

Hi. This is the first posting from The MathWorks to comp.soft-sys.matlab. I’m posting it from Stanford because we’re having trouble posting to newly establish groups, including comp.soft-sys.matlab, from the MathWorks machines in Massachusetts. We can post to old, established groups, but not to some new ones, including what is now the most important group for us. If anybody else is having similar difficulties, please let us know. Thanks to Michael Maurer at Stanford for initiating the group. The size of the vote in favor, and the level of participation this first week, are certainly good signs for an active, useful group.

At the MathWorks, we intend to follow the group’s activities, to respond individually to technical and informational queries, and to post general responses and announcements when we believe they are of broad interest. We certainly intend to respect the Net’s noncommercial culture.

We hope that many of the queries will be answered by other group participants. The discussion we’ve seen so far of MATLAB/Unix memory management is a good example of how this ought to work.

Thanks to all of you for your support of MATLAB. With your help, comp.soft-sys.matlab can be a valuable, and enjoyable, activity for all of us.

– Cleve Moler
Chairman and Chief Scientist
The MathWorks

And Cleve kept posting, always eager to teach people how to get their mathemetical computations done accurately and efficiently. For example, this 30-Jan-1993 post was in response to a question about computing factorials in MATLAB:

MATLAB does not have a factorial function, so n! must be computed by

prod(1:n)

or, possibly with roundoff error, by

gamma(n+1)

But, be careful, either of these quantities overflow for n > 170. If you actually want n! to compute something like

n!/(k!*(n-k)!)

for large n, you should use

exp(sum(log(1:n))-sum(log(1:k))-sum(log(1:(n-k))))

It’s not as slow as it looks, and it doesn’t overflow.

– Cleve Moler

Then there was this fellow named John Little, who started posting on the same day as Cleve and who kept up a steady stream of technical MATLAB nuggets like this one:

The MEX-file facility in MATLAB 4.0 includes a new routine called mexPutMatrix that allows you to plop a matrix directly back into the MATLAB workspace.

John Little

(At MathWorks, we generally call him “Jack.” He is our CEO.)

I noticed other MathWorks people jumping in, too. Clay Thompson answered one of my own questions in early February 1993. And then there was Loren Shure, who was answering a question about the quad function in March 1993. (Many of you know Loren from her Art of MATLAB blog.)

By following these MathWorks interactions in the early MATLAB community, I began to form a very favorable impression of the company and the people who worked there. When I saw Loren at a signal processing conference that spring, I introduced myself, and I volunteered to be a beta tester for the new image processing product that Loren could only hint about. By the fall of 1993, I had participated in the beta test and then interviewed (successfully) for a job. My family and I moved from Chicago to Massachusetts in December, and we’ve been here ever since!

Categories: Blogs

Friday MATLAB Mystery

Matlab Image processing blog - 2016, August 26 - 09:00

Who can tell me the significance of this number:

0.814723686393179

Update: 29-Aug-2016

Sven and Sam are correct. This the first number returned by the rand function in a given session, assuming no other calls to related random number functions (such as randn) have been made. For more information about this number and about random number generation in general, see Chapter 9 of Cleve Moler's book Numerical Computing with MATLAB.

Mikhail, the initial state used by MATLAB is the same initial state used in genrand_int32 in the reference implementation.

Categories: Blogs

See you at Burning Man!

Cory Doctorow - 2016, August 25 - 21:42

I’m about to switch off my email until September 5 and drive to Black Rock City for 10 days of incinerating the dude.


If you’re going this year, drop by Liminal Labs — with whom I am immensely privileged to camp — and have some cold brew and say hi! We’re at 5&F this year (look for the giant steel gate, the flaming chandelier, and the flying car).

I’m also giving my annual talk at Palenque Norte/Soft Landing which is at 8:00 & Botticelli this year. It’s called “When the better web we’re making crashes, how will we soften the landing?” and it’s at 5PM on Friday, Sept 2.

I’ll see you on the playa!

Categories: Blogs

Talking about the pro-security, anti-DRM business model on the O’Reilly Radar Podcast

Cory Doctorow - 2016, August 25 - 06:25


On this just-released episode of the O’Reilly Radar podcast (MP3), I talk about EFF’s lawsuit against the US government to invalidate Section 1201 of the DMCA, which will make it legal to break DRM in order to fix security vulnerabilities in the Internet of Things devices that, today, are almost invariable insecure, and are also designed to be as privacy-invading as possible (to create “monetizable” data-streams) — a brutal combo.



Auditing IoT products is a liability for security researchers

Think about the conditions under which IoT companies operate. Their business plan—the thing they show to VCs to get the money to go into the business—is to monetize data. They’re all designed with security as an afterthought. They’re all designed with the minimum viable security to make this product not immediately burst into flames after you put it inside your body or put your body inside of it. Even worse, security researchers face total, brutal liability for investigating these devices and telling people which ones are and aren’t safe. It is completely nightmarish.
New pro-security business models

Note: The Electronic Frontier Foundation is representing Bunnie Huang and Matthew Green in a case challenging the constitutionality of Section 1201 of the DMCA.

One of the things that our DMCA lawsuit would provide for is a pro-security business model. Imagine if you could start a commercial consultancy that would come in and deworm your IoT household. It could come in and jailbreak all the devices and check their firmware loads, and replace the firmware loads with open firmware or patched firmware, or something else that sits in between. All of those things, all that commercial stuff as well, is currently off-limits, and would be available in the same way that you can enable third-party parts and services if there are no legal impediments. The hardware service and support market in the U.S. for all classes of goods, from lawnmowers to cars to air conditioners to computers, is 2 to 4% of America’s GDP. It’s a gigantic multi-billion-dollar sector, and in many cases, these are small and medium-size enterprises.

Categories: Blogs

Binary image area filtering

Matlab Image processing blog - 2016, August 22 - 11:35

In my August 8 post about Pokemon Go (and I still can't quite believe that I did that), one of the processing steps was finding the centroid of the largest object in a binary image.

That reminded me of something that's been on my blog topic ideas list for a long time: filtering a binary image based on object size. Typically this operation is used as a kind of cleanup or preprocessing operation to remove small "noise-like" blobs.

Among the mathematical morphology folk, removing connected components that have an area smaller than some threshold is called area opening, and there's an Image Processing Toolbox function called bwareaopen that does it.

bw = imread('blobs.png'); imshow(bw) title('Original')

Keep objects containing at least 10 pixels.

bw2 = bwareaopen(bw,10); imshow(bw2) title('Area opening')

Long-time blog readers might remember a post from five years ago in which I invited feedback on the area opening terminology and the name of the function bwareaopen. I wondered in that post whether area opening was a little too jargony. Several people posted insightful comments.

Well, that discussion had an impact. A few release cycles later, in R2014b, the toolbox development team added a new function: bwareafilt. This function "keeps" a subset of objects in the binary image based on size. There are several ways to define the subset. Here are some examples:

Keep the 10 largest objects.

bw3 = bwareafilt(bw,10); imshow(bw3) title('10 largest objects')

Keep the 10 smallest objects.

bw4 = bwareafilt(bw,10,'smallest'); imshow(bw4) title('10 smallest objects')

Keep objects within a range of sizes.

bw5 = bwareafilt(bw,[20 50]); imshow(bw5) title('Size range: 20-50 pixels')

Keep objects with a minimum size by using Inf as the upper bound.

bw6 = bwareafilt(bw,[100 Inf]); imshow(bw6) title('Objects with at least 100 pixels')

Finally, let me show you a quick way to get a histogram of object sizes in an image.

bw_text = imread('text.png'); imshow(bw_text) t = regionprops('table',bw_text,'Area'); figure histogram(t.Area) title('Object sizes in text image') \n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016a

(and I still can't quite believe that I % did that), one of the processing steps was finding the centroid of the % largest object in a binary image. % % That reminded me of something that's been on my blog topic ideas list for % a long time: filtering a binary image based on object size. Typically % this operation is used as a kind of cleanup or preprocessing operation to % remove small "noise-like" blobs. % % Among the mathematical morphology folk, removing connected components % that have an area smaller than some threshold is called _area opening_, % and there's an Image Processing Toolbox function called |bwareaopen| that % does it. bw = imread('blobs.png'); imshow(bw) title('Original') %% % Keep objects containing at least 10 pixels. bw2 = bwareaopen(bw,10); imshow(bw2) title('Area opening') %% % Long-time blog readers might remember a in which % I invited feedback on the _area opening_ terminology and the name of the % function |bwareaopen|. I wondered in that post whether _area opening_ was % a little too jargony. Several people posted insightful comments. % % Well, that discussion had an impact. A new release cycles later, in % R2014b, the toolbox development team added a new function: |bwareafilt|. % This function "keeps" a subset of objects in the binary image based on % size. There are several ways to define the subset. Here are some % examples: % % Keep the 10 largest objects. bw3 = bwareafilt(bw,10); imshow(bw3) title('10 largest objects') %% % Keep the 10 smallest objects. bw4 = bwareafilt(bw,10,'smallest'); imshow(bw4) title('10 smallest objects') %% % Keep objects within a range of sizes. bw5 = bwareafilt(bw,[20 50]); imshow(bw5) title('Size range: 20-50 pixels') %% % Keep objects with a minimum size by using Inf as the upper bound. bw6 = bwareafilt(bw,[100 Inf]); imshow(bw6) title('Objects with at least 100 pixels') %% % Finally, let me show you a quick way to get a histogram of object sizes % in an image. bw_text = imread('text.png'); imshow(bw_text) %% t = regionprops('table',bw_text,'Area'); figure histogram(t.Area) title('Object sizes in text image') ##### SOURCE END ##### 606f806ddcc249ba80acc4a598d88162 -->

Categories: Blogs

Podcast: Live from HOPE on Radio Statler

Cory Doctorow - 2016, August 20 - 06:23

While I was in NYC to keynote the 11th Hackers on Planet Earth convention, I sat down with the Radio Statler folks and explained what I was going to talk about, as well as bantering with the hosts about the relative merits of DEFCON and HOPE and the secret to managing cons and marriages (MP3).

Categories: Blogs

Podcast: How we’ll kill all the DRM in the world, forever

Cory Doctorow - 2016, August 17 - 08:20

I’m keynoting the O’Reilly Security Conference in New York in Oct/Nov, so I stopped by the O’Reilly Security Podcast (MP3) to explain EFF’s Apollo 1201 project, which aims to kill all the DRM in the world within a decade.


A couple things changed in the last decade. The first is that the kinds of technologies that have access controls for copyrighted works have gone from these narrow slices (consoles and DVD players) to everything (the car in your driveway). If it has an operating system or a networking stack, it has a copyrighted work in it. Software is copyrightable, and everything has software. Therefore, manufacturers can invoke the DMCA to defend anything they’ve stuck a thin scrim of DRM around, and that defense includes the ability to prevent people from making parts. All they need to do is add a little integrity check, like the ones that have been in printers for forever, that asks, “Is this part an original manufacturer’s part, or is it a third-party part?” Original manufacturer’s parts get used; third-party parts get refused. Because that check restricts access to a copyrighted work, bypassing it is potentially a felony. Car manufacturers use it to lock you into buying original parts.

This is a live issue in a lot of domains. It’s in insulin pumps, it’s in voting machines, it’s in tractors. John Deere locks up the farm data that you generate when you drive your tractor around. If you want to use that data to find out about your soil density and automate your seed broadcasting, you have to buy that data back from John Deere in a bundle with seed from big agribusiness consortia like Monsanto, who license the data from Deere. This metastatic growth is another big change. It’s become really urgent to act now because, in addition to this consumer rights dimension, your ability to add things to your device, take it for independent service, add features, and reconfigure it are all subject to approval from manufacturers.

All of this has become a no-go zone for security researchers. In the last summer, the Copyright Office entertained petitions for people who have been impacted by Section 1201 of the DMCA. Several security researchers filed a brief saying they had discovered grave defects in products as varied as voting machines, insulin pumps and cars, and they were told by their counsel that they couldn’t disclose because, in so doing, they would reveal information that might help someone bypass DRM, and thus would face felony prosecution and civil lawsuits.


Cory Doctorow on legally disabling DRM (for good)
[Courtney Nash/O’Reilly]

Categories: Blogs

Playing Jackie Kennedy in The Tragedy of JFK

Casey McKinnon - 2016, August 15 - 12:26

I'm so excited to tell you all that I've been cast to play the iconic Jacqueline Bouvier Kennedy in the world premiere of The Blank's The Tragedy of JFK (as told by Wm. Shakespeare)

I don't know how to explain it, but when I heard about this new play about JFK told in the words of William Shakespeare, it awakened a dream in me that was hiding in the depths of my heart. Somewhere deep in my subconscious, I just knew that it was perfect for me and that I always did want to play Jackie Kennedy.

I left nothing to chance and lived by my personal motto of "no fate but what we make." I cried with joy when I got a callback, and expected to do the same if I was offered the role. The wait was excruciating. As a devout atheist, I prayed to no one, but just kept whispering my motto to myself whenever I felt nervous. At this point, it was out of my hands. The night after the callback, I saw a shooting star and instantly thought of the play, hoping it was a sign even though I don't believe in signs. I didn't make a wish (for fear of the monkey's paw!), but again I whispered my motto under my breath.

Finally, a couple of days later, I got the email.

Just like my acceptance from RADA a year earlier, I read and re-read the message a dozen times or more. I wasn't sure whether I was reading everything correctly or not. Had someone typed something wrong? No, they didn't; this is really happening!

I immediately started reading Jacqueline Bouvier Kennedy Onassis: The Untold Story by Barbara Leaming, a biography I had come across in my research over the past few weeks. I've been busy pinning information and images on Pinterest, watching videos and listening to old Jackie interviews on YouTube. I watched The Day Kennedy Died on Netflix, rented Camelot, and finally sat down to watch Oliver Stone's JFK. At this point, I'm listening to Caroline Kennedy's Jacqueline Kennedy: Historic Conversations on Life with John F. Kennedy, an audio book of the Schlesinger interviews from early 1964, and reading Mrs. Kennedy and Me, an intimate memoir written by Jackie's Secret Service agent Clint Hill, who ran up to the limousine after the shots rang out, climbed on the car and protected Jackie with his body as they drove away in the havoc and terror of that fateful day. I think my favorite find in all this research so far, however, is this delightful phone conversation with President Lyndon B. Johnson on December 2nd, 1963.

I've always had a soft spot for Jackie Kennedy. When I left for my high school prom, wearing big round sunglasses and a scarf to protect my hair from the wind in my dad's rented Sebring convertible, my mother called out, "you look just like Jackie O!" Previously, my mother had told me about her own experience on the day JFK died, and it always stuck with me. She had just started working as a secretary at a big investment firm in Montreal when it happened. Someone in her office heard the news on the radio and everybody stopped to listen. I had never experienced anything quite like it until I watched the twin towers fall on 9/11. I can still recall the stunned silence at McGill University that day when hundreds of students huddled around the television in the cafeteria basement of the Bronfman Building.

While Jackie and I grew up in different worlds and different times, we share so much in common. We were both born into Catholicism. We were both raised with the false idea that we were descended from royalty. We both hungered to get away from a cookie-cutter life. We both moved to Europe at the age of 19 and froze our asses off in bedrooms with no heating! We both learned multiple languages. We've both spent a lot of time around dignitaries. And we both worked as secretaries, and had short-lived careers as journalists before getting married (her for the Washington Times-Herald, and I for The Guardian).

Aside from the sheer joy of getting to play Jackie Kennedy in The Tragedy of JFK, I'm excited about this production for so many other reasons. I get to work with an incredible group of people, a director I admire, for a theatre company that I have a lot of respect for... and I get to do my favorite thing in the whole world: Shakespeare!

Previews begin on September 24th, and tickets are available here. Don't you dare miss it!

Categories: Blogs

Pokémon Go meets MATLAB

Matlab Image processing blog - 2016, August 8 - 07:55

Until about two weeks ago, I had given absolutely no thought to the possibility of a relationship between MATLAB and Pokémon Go, this summer's worldwide mobile gaming phenomenon. But then I heard about someone using some basic image processing techniques to hack the game by automating the search for PokéStops.

Well, I don't play Pokémon Go and I don't know what a PokéStop is, but I understood the basic idea behind the search automation.

Here is a screen shot from the game.

url = 'http://blogs.mathworks.com/steve/files/pokemon-go-screen.jpg'; rgb = imread(url); imshow(rgb)

(Thanks very much to the people who sent me screen shots, especially Haripriya and Chris.)

That geometric pattern of nested blue circles is a PokéStop. Our task is to find those. I'm going to show the basic outline of a solution with these steps:

1. Segment the image by color.

2. Clean up the segmentation using a morphological closing.

3. Compute the areas and centroids of the connected components in the segmentation.

4. Choose the largest object.

To get a quick idea of how to segment the image by color, I like to use the Color Thresholder, usually with the Lab color space. Here's a screen shot that shows how I have adjusted the a* and b* sliders to pick out the range of colors associated with the PokéStop.

Here's the resulting mask that I saved from the Color Thresholder.

imshow(BW)

Now let's use morphological closing to turn the PokéStop pattern into a single, connected blob.

BW2 = imclose(BW,strel('disk',20)); imshow(BW2)

Next, use regionprops to find all the connected components and compute their areas and centroids. In recent versions of the Image Processing Toolbox, you can tell regionprops to return the result as a table, which makes the results easier to read.

t = regionprops('table',BW2,'area','centroid') t = Area Centroid _____ ________________ 1157 37.43 665.14 13259 260.56 313.99 2 217 49.5 6 259 31.5 1 265 82 6 356.5 31.667 12 387.5 31.5

Finally, identify the table row with the biggest area, and get the corresponding centroid.

[~,j] = max(t.Area); location = t.Centroid(j,:) location = 260.5581 313.9893

Let's see how well that worked by superimposing the location on the original image.

imshow(rgb) hold on plot(location(1),location(2),'dy','MarkerSize',10,'MarkerFaceColor','y') hold off

There you go.

Catch 'em all!

\n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016a

> % % Here's the resulting mask that I saved from the % . imshow(BW) %% % Now let's use morphological closing to turn the PokéStop pattern % into a single, connected blob. BW2 = imclose(BW,strel('disk',20)); imshow(BW2) %% % Next, use % to find all the connected components and compute % their areas and centroids. In recent versions of the Image % Processing Toolbox, you can tell |regionprops| to return the % result as a table, which makes the results easier to read. t = regionprops('table',BW2,'area','centroid') %% % Finally, identify the table row with the biggest area, and get the % corresponding centroid. [~,j] = max(t.Area); location = t.Centroid(j,:) %% % Let's see how well that worked by superimposing the location on % the original image. imshow(rgb) hold on plot(location(1),location(2),'dy','MarkerSize',10,'MarkerFaceColor','y') hold off %% % There you go. % % Catch 'em all! ##### SOURCE END ##### 201f5d4adb1941158113b68b5bd905b7 -->

Categories: Blogs

Friday MATLAB Mystery

Matlab Image processing blog - 2016, August 5 - 09:49

There are some MathWorkers who like to try to stump each other with pictures of "mystery items." For example, last week someone posted the following picture and challenged others to guess what it is:

OK, blog readers, today I offer you a "Friday MATLAB Mystery."

A MATLAB designer I know has a habit of using this plot for design mocks:

Who can tell me what this plot is?

Bonus question: what is the mystery item pictured at the top of this post?

\n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016a

> % % OK, blog readers, today I offer you a "Friday MATLAB Mystery." % % A MATLAB designer I know has a habit of using this plot for design mocks: % % <> % % Who can tell me what this plot is? % % Bonus question: what is the mystery item pictured at the top of this % post? ##### SOURCE END ##### 4a3f4a00b9974fd6b571830445ed8f2e -->

Categories: Blogs

My Kansas City World Science Fiction Convention schedule

Cory Doctorow - 2016, August 4 - 11:35



I’m flying into Kansas City for part of Midamericon II, the 74th World Science Fiction Convention, and while there, I’ll be on panels, give a reading, and sit down with fans for a kaffeeklatsch.


Here’s my schedule:

Thursday:

Is Cyberpunk Still a Thing?
Thursday 12:00 – 13:00, 3501H (Kansas City Convention Center)
Cyberpunk hit with a big splash, but as personal computers became more prevalent, smaller, and portable, the genre seems to have faded. Or has it? Our panelists take a renewed look at the state of Cyberpunk at the ripe young age of 35.
Ms Pat Cadigan, Cory Doctorow (M), Matt Jacobson, Alvaro Zinos-Amaro, James Patrick Kelly, Patrick Nielsen Hayden

Friday
Patents, Copyrights, Trademarks, and Other Forms of Intellectual Property
Friday 10:00 – 11:00, 2502B (Kansas City Convention Center)
A look at the purpose of patents, copyrights, and trademarks. What is their historical purpose, how is the need for them changing, and where will they go in the future?
Cory Doctorow, Eric Flint, Allan Dyen-Shapiro (M), Sarah Frost, Lisa Macklem

An Idiot’s Guide Revisited, circa 2000
Friday 13:00 – 14:00, 2208 (Kansas City Convention Center)
It’s circa 2000 and authors Cory Doctorow and Karl Schroeder just published /The Complete Idiot’s Guide to Publishing Science Fiction/. Fast-forward 16 years later, and the world of publishing has evolved, but how much has it really changed? Cory and Karl take a look back and discuss what they got right, what they got wrong, and how things have changed over the years.
Karl Schroeder, Cory Doctorow, Patrick Nielsen Hayden

Reading: Cory Doctorow
Friday 16:00 – 16:30, 2202 (Readings) (Kansas City Convention Center)

Saturday
Kaffeeklatsch: Alexander James Adams, Cory Doctorow, Yanni Kuznia, Ada Palmer
Saturday 12:00 – 13:00, 2211 (KKs) (Kansas City Convention Center)
Alexander James Adams, Cory Doctorow, Ada Palmer, Yanni Kuznia

I hope to see you there!

Upcoming Appearances [Cory Doctorow/Craphound]

Categories: Blogs

Ineffective preallocation

Matlab Image processing blog - 2016, August 1 - 06:26

Today I want to explain a MATLAB coding mistake that I have seen even experienced MATLAB users make.

I was looking at some code on the File Exchange recently, and these lines caught my eye:

cm_data = zeros(m,3); hsv=rgb2hsv(cm); cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m)); cm_data=hsv2rgb(cm_data);

Specifically, I was struck by the first and third lines. The first line creates an all-zeros matrix. Then the third line throws away the matrix created by the first line, replacing it with the output of interp1.

I have seen code like this before. It results from a misunderstanding of the concept of preallocation in MATLAB.

In MATLAB, preallocation refers to creating a matrix (usually with zeros) prior to entering a loop that would otherwise repeatedly resize the matrix.

Here is an example. In the for-loop below, the size of the matrix x is increased by one element each time through the body of the loop.

x = 0; for k = 2:1000000 x(k) = x(k-1) + 5; end

In versions of MATLAB before R2011a, this kind of loop could be quite slow. The reason is that MATLAB would reallocate the memory space for the matrix x each time through the loop, resulting in $O(N^2)$ execution time overall. To avoid this performance penalty, the usual recommendation was to create the full-size matrix x before entering the loop, like this:

x = zeros(1,1000000); for k = 2:1000000 x(k) = x(k-1) + 5; end

Although automatic array growth got much more efficient in MATLAB R2011a (it is no longer $O(N^2)$), there is still some performance benefit to preallocation, which is why it is still described in the documentation.

In the code from the File Exchange, though, the matrix cm_data is not being grown in a loop. The result of the initial assignment, cm_data = zeros(m,3), is just discarded without ever being used.

The MATLAB Editor tries to tell you about this. Do you see the orange squiggle on the first line below?

If you hover over the squiggle with the mouse, you see this:

And if you then click on the Details button, you get a full explanation:

In summary, don't worry about putting in that call to zeros unless you are growing a matrix in a loop. If you later replace the variable with a completely new matrix returned by another function call, then the call to zeros is not helping you, and it might even slow down your code.

\n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016a

% (it is no longer $O(N^2)$), there is still some performance benefit to % preallocation, which is why it is still % . % % In the code from the File Exchange, though, the matrix |cm_data| is not % being grown in a loop. The result of the initial assignment, |cm_data = % zeros(m,3)|, is just discarded without ever being used. % % The MATLAB Editor tries to tell you about this. Do you see the orange % squiggle on the first line below? % % <> % % If you hover over the squiggle with the mouse, you see this: % % <> % % And if you then click on the Details button, you get a full explanation: % % <> % % In summary, don't worry about putting in that call to |zeros| unless you % are growing a matrix in a loop. If you later replace the variable with a % completely new matrix returned by another function call, then the call to % |zeros| is not helping you, and it might even slow down your code. ##### SOURCE END ##### 0b2286802748443f9a83ba9f122ca13e -->

Categories: Blogs

Adaptive thresholding for binarization

Matlab Image processing blog - 2016, July 25 - 08:01

Despite recent appearances on the blog, I still exist! It's just been a little crazier than usual for the last month or so.

Anyway ... I'm back, and I'm going to try to wrap things up about image binarization. In my 14-Jun-2016 post, I discussed the algorithm underlying imbinarize for the global thresholding case. Today I'm going to talk about the algorithm for the adaptive thresholding case.

Here's an image suffering from an extreme case of nonuniform illumination.

I = imread('printedtext.png'); imshow(I)

Here is the binarization using a global threshold.

bw1 = imbinarize(I); imshow(bw1) title('Global threshold')

And here is the binarization using an adaptive threshold. Note that we have to tell the function that the foreground pixels (representing text characters) are darker than the background pixels (the white paper).

bw2 = imbinarize(I,'adaptive','ForegroundPolarity','dark'); imshow(bw2) title('Adaptive threshold')

The algorithm used by |imbinarize(I,'adaptive',...) is sometimes called Bradley's method, for the paper by D. Bradley and G. Roth, "Adaptive Thresholding Using Integral Image," Journal of Graphics Tools, vol. 12, issue 2, pp. 13-21, 2007.

This method uses a large-neighborhood mean filter. If the input image pixel is more than a certain percentage greater than the mean filter, then it is set to white.

To perform large-neighborhood mean filtering (also called box filtering) efficiently, the implementation uses something called an integral image. With this technique, time required to perform mean filtering depends only on the number of image pixels. The time is independent of the neighborhood size. Maybe I'll discuss integral images and box filtering in a future post. In the meantime, you can look at integralImage and imboxfilt.

So how big is the mean filter neighborhood? Well, there's no fixed rule. This is another one of those magic numbers that bedevil image processing. The function imbinarize uses a square neighborhood that is about 1/8 of the smallest image dimension. This is just a heuristic rule that works reasonably well for a variety of images.

The function imbinarize does everything for you in one step. It computes the adaptive threshold image and then applies it to produce a binary output image. If you want the adaptive threshold image itself, or if you want more control over the how the adaptive threshold image is computed, then you can use adaptthresh.

Here is the adaptive threshold image for the printed text example shown above.

T = adaptthresh(I,'ForegroundPolarity','dark'); imshow(T) title('Adaptive threshold image')

When you use adaptthresh, you can control the neighborhood size directly. You can also specify other local background measurement methods, including median filtering and Gaussian filter.

Wrapping Up

With the new set of Image Processing Toolbox interfaces, using imbinarize as your one-step solution for both global and adaptive thresholding. Gain finer control over algorithm details, if you need to, by using the underlying functions otsuthresh and adaptthresh. The older functions, im2bw and graythresh, still exist for compatibility, but we encourage you to use the new functions in your new code.

\n'); d.write(code_string); // Add copyright line at the bottom if specified. if (copyright.length > 0) { d.writeln(''); d.writeln('%%'); if (copyright.length > 0) { d.writeln('% _' + copyright + '_'); } } d.write('\n'); d.title = title + ' (MATLAB code)'; d.close(); } -->


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2016a

, I discussed the algorithm underlying % % for the global thresholding case. Today I'm going to talk about the % algorithm for the adaptive thresholding case. % % Here's an image suffering from an extreme case of nonuniform % illumination. I = imread('printedtext.png'); imshow(I) %% % Here is the binarization using a global threshold. bw1 = imbinarize(I); imshow(bw1) title('Global threshold') %% % And here is the binarization using an adaptive threshold. Note that we % have to tell the function that the foreground pixels (representing text % characters) are darker than the background pixels (the white paper). bw2 = imbinarize(I,'adaptive','ForegroundPolarity','dark'); imshow(bw2) title('Adaptive threshold') %% % The algorithm used by |imbinarize(I,'adaptive',...) is sometimes called % Bradley's method, for the paper by D. Bradley and G. Roth, "Adaptive % Thresholding Using Integral Image," Journal of Graphics Tools, vol. 12, % issue 2, pp. 13-21, 2007. % % This method uses a large-neighborhood mean filter. If the input image % pixel is more than a certain percentage greater than the mean filter, % then it is set to white. % % To perform large-neighborhood mean filtering (also called _box filtering_) % efficiently, the implementation uses something called an _integral % image_. With this technique, time required to perform mean filtering % depends only on the number of image pixels. The time is independent of % the neighborhood size. Maybe I'll discuss integral images and box % filtering in a future post. In the meantime, you can look at % and % . % % So how big is the mean filter neighborhood? Well, there's no fixed rule. % This is another one of those magic numbers that bedevil image processing. % The function |imbinarize| uses a square neighborhood that is about 1/8 of % the smallest image dimension. This is just a heuristic rule that works % reasonably well for a variety of images. % % The function |imbinarize| does everything for you in one step. It % computes the adaptive threshold image and then applies it to produce a % binary output image. If you want the adaptive threshold image itself, or % if you want more control over the how the adaptive threshold image is % computed, then you can use % . % % Here is the adaptive threshold image for the printed text example shown % above. T = adaptthresh(I,'ForegroundPolarity','dark'); imshow(T) title('Adaptive threshold image') %% % When you use |adaptthresh|, you can control the neighborhood % size directly. You can also specify other local background measurement % methods, including median filtering and Gaussian filter. % % *Wrapping Up* % % With the new set of Image Processing Toolbox interfaces, using % |imbinarize| as your one-step solution for both global and adaptive % thresholding. Gain finer control over algorithm details, if you need to, % by using the underlying functions |otsuthresh| and |adaptthresh|. The % older functions, |im2bw| and |graythresh|, still exist for compatibility, % but we encourage you to use the new functions in your new code. ##### SOURCE END ##### fe9ea6458a2b48c3892cb04123763a2a -->

Categories: Blogs

EFF is suing the US government to invalidate the DMCA’s DRM provisions

Cory Doctorow - 2016, July 21 - 07:24

The Electronic Frontier Foundation has just filed a lawsuit that challenges the Constitutionality of Section 1201 of the DMCA, the “Digital Rights Management” provision of the law, a notoriously overbroad law that bans activities that bypass or weaken copyright access-control systems, including reconfiguring software-enabled devices (making sure your IoT light-socket will accept third-party lightbulbs; tapping into diagnostic info in your car or tractor to allow an independent party to repair it) and reporting security vulnerabilities in these devices.


EFF is representing two clients in its lawsuit: Andrew “bunnie” Huang, a legendary hardware hacker whose NeTV product lets users put overlays on DRM-restricted digital video signals; and Matthew Green, a heavyweight security researcher at Johns Hopkins who has an NSF grant to investigate medical record systems and whose research plans encompass the security of industrial firewalls and finance-industry “black boxes” used to manage the cryptographic security of billions of financial transactions every day.

Both clients reflect the deep constitutional flaws in the DMCA, and both have standing to sue the US government to challenge DMCA 1201 because of its serious criminal provisions (5 years in prison and a $500K fine for a first offense).

The US Trade Rep has propagated the DMCA’s anticircumvention rules to most of the world’s industrial nations, and a repeal in the US will strengthen the argument for repealing their international cousins.

Huang has written an inspirational essay explaining his reasons for participating in this suit, explaining that he feels it is his duty to future generations:

Our recent generation of Makers, hackers, and entrepreneurs have developed under the shadow of Section 1201. Like the parable of the frog in the well, their creativity has been confined to a small patch, not realizing how big and blue the sky could be if they could step outside that well. Nascent 1201-free ecosystems outside the US are leading indicators of how far behind the next generation of Americans will be if we keep with the status quo.

Our children deserve better.

I can no longer stand by as a passive witness to this situation. I was born into a 1201-free world, and our future generations deserve that same freedom of thought and expression. I am but one instrument in a large orchestra performing the symphony for freedom, but I hope my small part can remind us that once upon a time, there was a world free of such artificial barriers, and that creativity and expression go hand in hand with the ability to share without fear.

The EFF’s complaint, filed minutes ago with the US District Court, is as clear and comprehensible an example of legal writing as you could ask for. It builds on two recent Supreme Court precedents (Golan and Eldred), in which the Supremes stated that the only way to reconcile free speech with copyright’s ability to restrict who may utter certain words and expressions is fair use and other exemptions to copyright, which means that laws that don’t take fair use into account fail to pass constitutional muster.

In this decade, more and more companies have figured out that the DMCA gives them the right to control follow-on innovation and suppress embarrassing revelations about defects in their products; consequently, DMCA 1201-covered technologies have proliferated into cars and tractors, medical implants and home security systems, thermostats and baby-monitors.

With this lawsuit, the EFF has fired a starter pistol in the race to repeal section 1201 of the DMCA and its cousins all over the world: to legitimize the creation of commercial businesses that unlock the value in the gadgets you’ve bought that the original manufacturers want to hoard for themselves; to open up auditing and disclosure on devices that are disappearing into our bodies, and inside of which we place those bodies.

I’ve written up the lawsuit for the Guardian:


Suing on behalf of Huang and Green, EFF’s complaint argues that the wording of the statute requires the Library of Congress to grant exemptions for all conduct that is legal under copyright, including actions that rely on fair use, when that conduct is hindered by the ban on circumvention.

Critically, the supreme court has given guidance on this question in two rulings, Eldred and Golan, explaining how copyright law itself is constitutional even though it places limits on free speech; copyright is, after all, a law that specifies who may utter certain combinations of words and other expressive material.

The supreme court held that through copyright’s limits, such as fair use, it accommodates the first amendment. The fair-use safety valve is joined by the “idea/expression dichotomy”, a legal principle that says that copyright only applies to expressions of ideas, not the ideas itself.

In the 2015 DMCA 1201 ruling, the Library of Congress withheld or limited permission for many uses that the DMCA blocks, but which copyright itself allows – activities that the supreme court has identified as the basis for copyright’s very constitutionality.

If these uses had been approved, people such as Huang and Green would not face criminal jeopardy. Because they weren’t approved, Huang and Green could face legal trouble for doing these legitimate things.


MATTHEW GREEN, ANDREW HUANG and ALPHAMAX, LLC v U.S. DEPARTMENT OF JUSTICE,
LORETTA LYNCH: COMPLAINT FOR DECLARATORY
AND INJUNCTIVE RELIEF
[EFF]

America’s broken digital copyright law is about to be challenged in court
[Cory Doctorow/The Guardian]

Why I’m Suing the US Government
[Andrew “bunnie” Huang]

Section 1201 of the DMCA Cannot Pass Constitutional Scrutiny

[Kit Walsh/EFF]

(Image: Bunnie Huang, Joi Ito, CC-BY)

Categories: Blogs

Comicon Schedule!

Flog - 2016, July 18 - 19:30

Hey all, here’s my COMICON SCHEDULE!

Thursday:
12-1pm Geek and Sundry Panel at Indigo Ballroom (Badge needed)
2pm: Nerd HQ Panel

Friday
10:30-11:30am: ConMan Panel Hall H (Badge Needed)
2:45pm: Q/A at Petco Park Stage

Saturday:
4-4:45pm MST3K Panel at Petco Park Stage
5:15-6:15pm MST3K SHOUT! Book Signing (Badge needed)
8:30-9:30pm MST3K Panel Room 24ABC (Badge needed)

Come by and say hi if you have time!

Categories: Blogs

My interview on Utah Public Radio’s “Access Utah”

Cory Doctorow - 2016, July 12 - 10:24

Science fiction novelist, blogger and technology activist Cory Doctorow joins us for Tuesday’s AU. In a recent column, Doctorow says that “all the data collected in giant databases today will breach someday, and when it does, it will ruin peoples’ lives. They will have their houses stolen from under them by identity thieves who forge their deeds (this is already happening); they will end up with criminal records because identity thieves will use their personal information to commit crimes (this is already happening); … they will have their devices compromised using passwords and personal data that leaked from old accounts, and the hackers will spy on them through their baby monitors, cars, set-top boxes, and medical implants (this is already hap­pening)…” We’ll talk with Cory Doctorow about technology, privacy, and intellectual property.

Cory Doctorow is the co-editor of popular weblog Boing Boing and a contributor to The Guardian, Publishers Weekly, Wired, and many other newspapers, magazines and websites. He is a special consultant to the Electronic Frontier Foundation, a non-profit civil liberties group that defends freedom in technology law, policy, standards and treaties. Doctorow is also an award-winning author of numerous novels, including “Little Brother,” “Homeland,” and “In Real Life.”

MP3

Categories: Blogs