You are hereFeed aggregator

Feed aggregator


Cluster-based image display

Matlab Image processing blog - 2013, April 1 - 03:00

Although this is the time of year that I normally mention some of the new features from the "a" release, today I thought I would focus on a feature added several releases ago that I think deserves more attention: parallel cluster-based image display. I can't remember exactly when this was released; I think it might have been R2011c.

Anyway, it turns out image display speed can be dramatically increased if we exploit the capabilities of today's massive parallel computing clusters. You start by opening a MATLAB pool from your desktop session using the Parallel Computing Toolbox function matlabpool. The Parallel Computing Toolbox has a new cluster profile that makes it easy to set things up for fast image display:

matlabpool image-display

Once the pool is configured, then the Image Processing Toolbox function imshow automatically uses the workers in the pool.

Let's try it with my blog author picture:

(I'm writing this blog post at home, so for a cluster I'll be using my home-brew video game console, which runs on a cluster of 128 TRS-80s.)

imshow

Here's what the display looks like on worker #37:

And here is the display on worker #92:

If you look carefully, you can see that the pixel block is not exactly the same size on the two workers. That's because of the automatic worker load balancing feature. Way cool!

Let's get down to some numbers. Specifically, I was interested to see how well image display performance scales with the number of workers. I used my function timeit to measure the display speed as I varied the number of workers. The plot below is "normalized speed-up." That is, 1 is the image display speed for normal MATLAB, with no use of the Parallel Computing Toolbox.

As you can see, we get almost perfectly linear scaling with the number of workers. (I'm not sure what's going on with that blip on the left. I think it might have been caused by a bad tape unit on worker #25.)

So, Parallel Computing Toolbox users, please give this a try and let us know about your experience!

Before I wrap it up for today, I can't resist giving a hint about future development directions. (Long-time readers know how much MathWorks loves to preannounce features.) We recently got our hands on one of the experimental new superfluidic clusters. Early indications are that we'll be able to get image display speed to scale with the square of the number of workers! Woo-hoo!

\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® R2013a

I thought I would % focus on a feature added several releases ago that I think deserves more % attention: parallel cluster-based image display. I can't remember exactly % when this was released; I think it might have been R2011c. % % Anyway, it turns out image display speed can be dramatically increased if % we exploit the capabilities of today's massive parallel computing % clusters. You start by opening a MATLAB pool from your desktop session % using the Parallel Computing Toolbox function |matlabpool|. The Parallel % Computing Toolbox has a new cluster profile that makes it easy to set % things up for fast image display: % % matlabpool image-display % % Once the pool is configured, then the Image Processing Toolbox function % |imshow| automatically uses the workers in the pool. % % Let's try it with my blog author picture: % % <> % % (I'm writing this blog post at home, so for a cluster I'll be using my % home-brew video game console, which runs on a cluster of 128 % .) % % imshow % % Here's what the display looks like on worker #37: % % <> % % And here is the display on worker #92: % % <> % % If you look carefully, you can see that the pixel block is not exactly % the same size on the two workers. That's because of the automatic worker % load balancing feature. Way cool! % % Let's get down to some numbers. Specifically, I was interested to see how % well image display performance scales with the number of workers. I used % my function to measure the display speed as I varied the number of workers. % The plot below is "normalized speed-up." That is, 1 is the image display % speed for normal MATLAB, with no use of the Parallel Computing Toolbox. % % <> % % As you can see, we get almost perfectly linear scaling with the number of % workers. (I'm not sure what's going on with that blip on the left. I % think it might have been caused by a bad tape unit on worker #25.) % % So, Parallel Computing Toolbox users, please give this a try and let us % know about your experience! % % Before I wrap it up for today, I can't resist giving a hint about future % development directions. (Long-time readers know how much MathWorks loves % to preannounce features.) We recently got our hands on one of the % experimental new superfluidic clusters. Early indications are that we'll % be able to get image display speed to scale with the *square* of the % number of workers! Woo-hoo! ##### SOURCE END ##### 17b585bcd58b412385e25985ca4e9738 -->

Categories: Blogs

New electric bike added to the fleet!

Green City Acres - 2013, March 31 - 12:49

An epic thank you to Kelowna Cycle for providing us with a new electric pedal assist Bionix! We’ll be pulling a lot more loads and moving a lot faster now.

Thanks Pat and the whole crew!

Categories: Blogs

Interview on NPR’s Off-Topic

Cory Doctorow - 2013, March 30 - 14:15


The NPR show OffTopic aired an episode called Give and Take: Pirates, Profiteers, and Art in the Age of Appropriation, and spoke to me for it. It's a really interesting listen!

MP3 link

Categories: Blogs

Speaking in Bradford tomorrow

Cory Doctorow - 2013, March 29 - 01:36

Here's details of the public event I'm doing in Bradford while I'm in town for Eastercon: I'll be at the 1in12 Club, as part of an event called "Can Technology Save the City?" that runs from 12-6. I'll be there around 1430h. Hope you'll come out!

Categories: Blogs

How the amazing UK cover for Rapture of the Nerds came to be

Cory Doctorow - 2013, March 29 - 01:31


I'm really impressed with the cover of the UK edition of Rapture of the Nerds, the novel I wrote with Charlie Stross. But it turns out that producing that cover was quite a journey. Designer Martin Stiff was kind enough to share his notes on the process, along with all the proto covers he produced for the UK publisher, Titan Books:


Designing book covers is the best job in the goddamn world. If you're lucky, like we are at Amazing15, you get to work with incredibly talented and lovely people, on some of the most fiendishly interesting projects you can't even begin to imagine without the aid of viralised nootropics.

When the incredibly talented and lovely Cath at Titan Books asked us to design the UK cover for Cory Doctorow and Charles Stross' The Rapture of the Nerds we braced ourselves. If you haven't read it, do it now. The book is a melting pot of brain-warping ideas, every time you think you get a handle on what it is, what it means, it shifts in your hands like an organic Rubik's cube.



Books which can manipulate reality aren't easy to design covers for. When you start a new project there's generally two initial ways in: 1) you step into it and find a moment, a scene, an element and pin your cover design on that or 2) you step back and look at the overall picture - try and find the theme. But what do you do when that picture seems to keep changing? The answer is, you keep chasing it. And what happens when there's other people involved in the process, each of whom has their *own* take on the book, a take which fluctuates as wildly as your own? The answer is you chase even harder and you don't look back.



The first ideas we turned in were turned down. They looked non-fiction (v2), or too young (v3). Version 4 hung around for a while but it quickly became too *normal* and that's just not something the novel is, so we threw it out. We fiddled with icons and graphics (v5, v6) and impossible shapes (v7) to match the impossible shape of the story but each time the book out-thought us and proved us wrong. Version 8 hung around for a while, but it still didn't feel *right* dammit, it felt like a good book cover but Nerds isn't *just* a 'good book', it's so much more than that. For a while there we lost the plot entirely (v9 was so wrong it had to be fired into the heart of the sun to destroy it), and when we came back up we played with colours and abstract patterns like madmen. Version 10 and 13 had something – after weeks of getting dirty with angry covers that weren't right we liked the simple cleanliness and easy lines. It felt like a breath of fresh air. It felt like The Rapture of the Nerds.





We chased harder. We imagined a bright spectrum filtered through a fractured pattern, clean fonts with nothing to hide. We got close. We kept the chaos subtle, a radiation of binary noise printed in spot varnish so you can only see it in angled light but you can feel it all the time under your fingertips. We got close and we caught it (v15). It wasn't easy, but if it gets easy, you're doing it wrong. We've just finished designing the covers to Doctorow's Pirate Cinema and Homeland. Designing book covers is the best job in the goddamn world.

Martin Stiff, Amazing15

Categories: Blogs

What problem are we trying to solve in the copyright wars?

Cory Doctorow - 2013, March 28 - 09:14

My latest Guardian column is "Copyright wars are damaging the health of the internet" and it looks at what we really need from proposed solutions to the copyright wars:

I've sat through more presentations about the way to solve the copyright wars than I've had hot dinners, and all of them has fallen short of the mark. That's because virtually everyone with a solution to the copyright wars is worried about the income of artists, while I'm worried about the health of the internet.

Oh, sure, I worry about the income of artists, too, but that's a secondary concern. After all, practically everyone who ever set out to earn a living from the arts has failed – indeed, a substantial portion of those who try end up losing money in the bargain. That's nothing to do with the internet: the arts are a terrible business, one where the majority of the income accrues to a statistically insignificant fraction of practitioners – a lopsided long tail with a very fat head. I happen to be one of the extremely lucky lotto winners in this strange and improbable field – I support my family with creative work – but I'm not parochial enough to think that my destiny and the destiny of my fellow 0.0000000000000000001 percenters are the real issue here.

What is the real issue here? Put simply, it's the health of the internet.

Copyright wars are damaging the health of the internet

Categories: Blogs

Schedule for EasterCon in Bradford

Cory Doctorow - 2013, March 28 - 02:41

I'm heading to Bradford tomorrow for Eight Squared Con, the 2013 Eastercon. I'm appearing on several programme items:

* Friday, 17h: Reading, Hawthorn Room

* Saturday, 12h: "On Twitter, Everyone Can Hear You Scream," Boardroom (panel)

* Saturday, 13h: Book launch for RAPTURE OF THE NERDS, Conservatory

* Saturday, 19h: "Genre Get-Together: Science Fiction," Conservatory (signing)

* Sunday, 12h: "Ready, Steady, Flash," Boardroom (live flash fiction writing)

I'm also doing something in town on Saturday (details TBD) with the 1 in 12 Library Book Club.

Categories: Blogs

James Perse: Most popular TV shirt of all time?

Belmont - 2013, March 26 - 15:11

I buy a lot of clothes to wear on camera, and over the years, I’ve begun to pay close attention to what other women are wearing onscreen. For example, I realized that Liz Lemon and I share a great number of items (mostly J. Crew and Theory tops) and I even spotted last Winter’s Peter Pan collar sweater on The Mindy Project.

But there is one shirt that I have seen on TV and in film more than any other: the James Perse contrast panel shirt.

I first noticed it on Skyler White. Then on Debra Morgan. Most recently, Andrea from The Walking Dead has been sporting it in several colors. Actually, all of these characters own the shirt in at least two different hues. Weirdly, the mom from Silver Linings Playbook was also wearing it.

Why is this shirt so great for on-camera?
1. It comes in a lot of different colors. More wardrobe options.
2. It’s a button up, which can be sexified up or more formal.
3. It’s comfortable and has some give to it, so it’s almost always flattering.

Anyhow, I own it in black and white. It rocks. I have no other reason for posting this other than the fact that I’ve noticed it for so long that I had to tell someone else (you, the internet).

No related posts.

Categories: Blogs

Announcing our new bike sponsor, Kelowna Cycle!

Green City Acres - 2013, March 26 - 12:04

Kelowna Cycle is now the official bike shop sponsor of Green City Acres!

We rely on them for all our bike maintenance, repairs, and new equipment. Kelowna Cycle is a bike shop that caters to all needs. From kids to adult bikes, mountain, road, cruisers, commuters, utility, and now electric assists, they cover all the bases. From humble beginnings, Pat Rosen started working as a mechanic at Kelowna Cycle in 1993, and then purchases the store in 2008. Pat and the crew at Kelowna Cycle are an inspiration to us at GCA, as a business that operates with integrity and has deep roots in the community. You can expect the best customer service and knowledgable staff whenever you head into either of their locations.

The main store is at 2949 Pandosy Street, and the Hub is at 1461 Sutherland Ave.

 

Categories: Blogs

IAEA Reviews Poland’s Progress in Nuclear Power Development

IAEA - 2013, March 26 - 10:07

An IAEA-led team of international experts who reviewed Poland’s programme for introducing nuclear power found that significant progress has been made in the development of the country’s nuclear infrastructure.

Categories: Blogs

IAEA’s Nuclear Energy Management School Opens in U.S.A.

IAEA - 2013, March 26 - 07:06

After successful stints in Italy, Japan and the United Arab Emirates, the IAEA’s School for Nuclear Energy Management is now underway in Texas, USA.

Categories: Blogs

Geek and Sundry: Coming back for a Second Year!

Flog - 2013, March 25 - 18:00

Hey guys!

I’ve been more busy than I have ever been these past few months, and trying to take some time for myself to figure out what’s next (good luck with that Felicia haha) but I’m VERY pleased to announce that Geek and Sundry will be releasing content for another year!

I made this video below as a result of some of my journaling and soul searching lately, I hope it makes you at least think about Geek Culture, whether you agree with me or not.

Re-defining WHY I am doing what I do really gave me the courage and motivation to go forward this year with new eyes, and a clear heart.  I’m actually really excited to change things up!  I like rolling the dice

Just for the curious and inquiring:
Tabletop, Space Janitors and Vaginal Fantasy are coming back this year (they all premiere next week). We have a BUNCH of new shows throughout the year, with shorter runs and more varied talent, to give you more variety (especially in the gaming area). The Flog will come back only sporadically while I am at conventions or travelling, I will be focusing on acting on the channel, developing content and talent searching for fresh voices to cultivate, and doing other shorter run shows like the one I’m starting on Monday, Felicia’s Ark (it’s about choosing which video game characters I’m taking with me after a theoretical flood happens, haha.)

I know this dialing back of The Flog is going to disappoint some, but I want to make it clear I’m trying to free up my schedule to focus on guiding the channel content, and perhaps creating another show, which takes a TON of time (it took me a year to come up with the Guild characters before I wrote the first episode).  As an artist I need some space to figure out if and when I can make something new, that I’ll love as much as The Guild, that YOU will love as much as The Guild.

And FYI the future of the Guild is still up in the air, and since we ended it so well with season 6 I felt like it was time to take a break.  I’ll see what happens, you never know!

I’m very excited to discover new voices and shift Geek and Sundry to really reflect what I love even more this year. Thank you for being on this journey with us, and I appreciate your watching!

Categories: Blogs

Down and Out in the Magic Kingdom read-aloud part 02

Cory Doctorow - 2013, March 25 - 11:33

As I mentioned in my March Locus column, I'm celebrating the tenth anniversary of Down and Out in the Magic Kingdom by planning a prequel volume. As part of that planning, I'm going to read aloud the entire text of that first book into the podcast, making notes on the book as I go. Here's part two.

Mastering by John Taylor Williams: [email protected]

John Taylor Williams is a audiovisual and multimedia producer based in Washington, DC and the co-host of the Living Proof Brew Cast. Hear him wax poetic over a pint or two of beer by visiting livingproofbrewcast.com. In his free time he makes "Beer Jewelry" and "Odd Musical Furniture." He often "meditates while reading cookbooks."

MP3 Link

Categories: Blogs

Launching the UK edition of Rapture of the Nerds TODAY at Forbidden Planet London

Cory Doctorow - 2013, March 22 - 22:49


Hey, Londoners! I'll be launching the UK edition of Rapture of the Nerds today at 1PM at Forbidden Planet. Although the book is available across the country at finer stores, this will be your only chance to stroke the marvellous 3D printed Space Marine Stross and have your picture taken with it.

Categories: Blogs

Letter from a young reader about Little Brother

Cory Doctorow - 2013, March 22 - 22:19


A young man named Alex came out to my Decatur, GA Homeland tour-stop and we had a charming (if brief) conversation, and subsequently snapped this quite wonderful photo. One of Alex's teachers subsequently wrote to me to say that Alex had taken high academic honors in a Letters About Literature contest about Little Brother, and he was kind enough to allow me to reproduce both the photo and the letter here.

Thanks, Alex!

Dear Cory Doctorow,

Little Brother is one of those drastically important books that deals with real issues affecting everyone. This book was, in my opinion, more than just a book; it was a persuasive, life-changing book, the kind of gem that comes around too infrequently.

Before I read Little Brother I was scared to try something different. I surrounded myself with the same old young-adult novels (you know- goes on a quest, learns many things, big fight with a troll, the end) and never dared to step out of my little box.

One day during the sixth grade I saw a kid with too many teeth sitting in a dusty corner, reading Little Brother, and asked him what it was about. He shrugged and muttered something incoherent about Harajuku Fun Madness. When I arrived at home I looked up the book on the internet. Before long I discovered your website, and became intrigued by the fact that you were just giving away your e-books.

The book shipped in two days.

I am always thinking. Constantly tossing up an idea, usually shooting it down, tossing up another one, sometimes it flies, I wait for it to crash, then I walk over to it and shoot it another three or four times for good measure. The few months before I read Little Brother this had dumbed down a bit. I could feel it, like I was wearing earplugs, and only low, muffled, blurry ideas wandered through occasionally to stop and say hi before continuing on their way.

After (and during) the reading of Little Brother the haze had lifted and was replaced by an energetic excitement that jumpstarted my brain to life. My neurons hummed like lawnmowers. A refreshing feeling of urgency and eagerness surged through me-- a feeling I’d not experienced since being eight years old on Christmas. And I started thinking again.

I put my flawless (yeah, right) guess-and-test technique to work, meticulously weeding through all the information to make sense of things. I realized just how possible the police-state situation could be- after 9/11 security everywhere was increased and tightened. The scanners updated. The rules stricter. The pat-downs more, ahem, thorough. What if this happened, but on a much larger scale?

Also, I’m a bit more paranoid. I know about those looming possibilities, terrifying ones- that technology could be used against me, that my freedom is more fragile than I thought. Already I’ve begun questioning the things presented to me as fact. I look at something and decide for myself if it’s the opinion I want to have.

My favorite part about Little Brother is how, in some way or another, it opened me up to so many other books and authors- Neil Gaiman, Alan Moore, Jack Kerouac, George Orwell, the list could go on and on.

Little Brother was and still remains the most important book I’ve ever read. If I had not read your book I would be awfully different, and probably much more ignorant and stubborn. Because of your book I started writing. I read more. I think more. You have written a book that is not only good, but life-changing as well. Thanks.

Sincerely,

Alex

Categories: Blogs

Haiti Moves Towards A Comprehensive Approach to Cancer Control

IAEA - 2013, March 22 - 08:39

An IAEA integrated mission review to Haiti was recently completed as part of the Agency’s Programme of Action on Cancer Therapy (PACT); recommendations will help guide Haitian health authorities in the drafting of a national cancer control plan.

Categories: Blogs

Sharing Water in the Parched Sahel

IAEA - 2013, March 22 - 06:24

World Water Day 2013 focuses on the opportunities for cooperation in the use of fresh water resources, and the IAEA supports such sustainable water resource use by helping countries measure and monitor their shared fresh water resources.

Categories: Blogs

Signing Rapture of the Nerds at Forbidden Planet London tomorrow

Cory Doctorow - 2013, March 22 - 00:56


Hey, Londoners! A reminder that I'll be signing the UK edition of Charlie Stross's and my novel Rapture of the Nerds, tomorrow at 1PM at Forbidden Planet. Charlie can't make it, so I have fashioned a cunning 3D printed Space Marine Stross to accompany me, which you may rub for good luck if you attend.

Categories: Blogs

Revisiting dctdemo – part 3

Matlab Image processing blog - 2013, March 21 - 13:14

This is the third part of my plan to rewrite an Image Processing Toolbox example from 20 years ago using more modern MATLAB language features. I got the idea from Dave Garrison's recent article on writing MATLAB apps.

Here's the old app I'm trying to reinvent:

And here's what I had working the last time:

The code isn't doing any actual DCT computations yet. The idea is to compute 8-by-8 block DCTs, zero out the least significant DCT coefficients of each block, and then reconstruct the image by computing the inverse DCT of each 8-by-8 block.

Let me show how this will work on the sample image I'm using for the app:

pout = imread('pout.tif'); pout2 = pout(1:240,:); I = im2double(adapthisteq(pout2)); imshow(I)

First, use blockproc to compute the 8-by-8 2-D DCTs.

f = @(block) dct2(block.data); A = blockproc(I,[8 8],f); imshow(A,[]) title('DCT coefficients')

Second, I want to compute the variances of each of the 64 coefficients. That is, compute the variance of the (1,1) DCT coefficients from each block, the variance of the (1,2) DCT coefficients from each block, and so on. I'll use the computed variances to determine which DCT coefficients to keep and which to zero out. To do this, I'll rearrange the elements from the previous step so that the corresponding DCT coefficients are together in the columns of a 64-column matrix.

B = im2col(A,[8 8],'distinct')'; vars = var(B); plot(vars) title('Variances of the 64 DCT coefficients')

Next, suppose we want to keep the 3 block DCT coefficients with the highest variances. I'll use sort to figure out which ones to keep.

[~,idx] = sort(vars,'descend'); keep = idx(1:3) keep = 1 9 2

For an 8-by-8 block of DCT coefficients, index values 1, 9, and 2 correspond to the upper-left DCT coefficient and the two coefficients just the right and down from it. Let's keep just those coefficients.

B2 = zeros(size(B)); B2(:,keep) = B(:,keep);

Now I'll rearrange the columns back into blocks and reconstruct the image by computing the inverse DCT of each block.

C = col2im(B2',[8 8],size(I),'distinct'); finv = @(block) idct2(block.data); D = blockproc(C,[8 8],finv); imshow(D) title('Image reconstructed from 3 DCT coefficients per block')

This algorithm code into a local function to go at the bottom of my app code file, like this:

function I2 = reconstructImage(I,n) % Reconstruct the image from n of the DCT coefficients in each 8-by-8 % block. Select the n coefficients with the largest variance across the % image.% Compute 8-by-8 block DCTs. f = @(block) dct2(block.data); A = blockproc(I,[8 8],f);% Compute DCT coefficient variances and decide % which to keep. B = im2col(A,[8 8],'distinct')'; vars = var(B); [~,idx] = sort(vars,'descend'); keep = idx(1:n);% Zero out the DCT coefficients we are not keeping. B2 = zeros(size(B)); B2(:,keep) = B(:,keep);% Reconstruct image using 8-by-8 block inverse % DCTs. C = col2im(B2',[8 8],size(I),'distinct'); finv = @(block) idct2(block.data); I2 = blockproc(C,[8 8],finv); end

I already have an update method in my class, so I can add code to that method that will compute the reconstructed image and error image. Here's the revised update method:

function update(app) recon_image = reconstructImage(app.OriginalImage, ... app.NumDCTCoefficients); diff_image = imabsdiff(app.OriginalImage, recon_image); imshow(app.OriginalImage,'Parent',app.OriginalImageAxes); title(app.OriginalImageAxes,'Original Image'); imshow(recon_image,'Parent',app.ReconstructedImageAxes); title(app.ReconstructedImageAxes,'Reconstructed Image'); imshow(diff_image,[],'Parent',app.ErrorImageAxes); title(app.ErrorImageAxes,'Error Image'); imshow(zeros(size(app.OriginalImage)),'Parent',app.MaskAxes); title(app.MaskAxes,'DCT Coefficient Mask'); drawnow; end

Although I don't have all the interactive behavior wired up yet, and don't have the DCT coefficient mask visualization done yet, the app runs and looks a bit more finished than it did before. It now shows the results for reconstructing the image from 3 DCT coefficients per block.

I think it'll take just one more post to finish making the rest of this app work.

\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® R2013a

on writing MATLAB apps. % % Here's the old app I'm trying to reinvent: % % <> % % And here's what I had working the last time: % % <> % % The code isn't doing any actual DCT computations yet. The idea is to % compute 8-by-8 block DCTs, zero out the least significant DCT % coefficients of each block, and then reconstruct the image by computing % the inverse DCT of each 8-by-8 block. % % Let me show how this will work on the sample image I'm using for the app: pout = imread('pout.tif'); pout2 = pout(1:240,:); I = im2double(adapthisteq(pout2)); imshow(I) %% % First, use |blockproc| to compute the 8-by-8 2-D DCTs. f = @(block) dct2(block.data); A = blockproc(I,[8 8],f); imshow(A,[]) title('DCT coefficients') %% % Second, I want to compute the variances of each of the 64 coefficients. % That is, compute the variance of the (1,1) DCT coefficients from each % block, the variance of the (1,2) DCT coefficients from each block, and so % on. I'll use the computed variances to determine which DCT coefficients % to keep and which to zero out. To do this, I'll rearrange the elements % from the previous step so that the corresponding DCT coefficients are % together in the columns of a 64-column matrix. B = im2col(A,[8 8],'distinct')'; vars = var(B); plot(vars) title('Variances of the 64 DCT coefficients') %% % Next, suppose we want to keep the 3 block DCT coefficients with the % highest variances. I'll use |sort| to figure out which ones to keep. [~,idx] = sort(vars,'descend'); keep = idx(1:3) %% % For an 8-by-8 block of DCT coefficients, index values 1, 9, and 2 % correspond to the upper-left DCT coefficient and the two coefficients % just the right and down from it. Let's keep just those coefficients. B2 = zeros(size(B)); B2(:,keep) = B(:,keep); %% % Now I'll rearrange the columns back into blocks and reconstruct the image % by computing the inverse DCT of each block. C = col2im(B2',[8 8],size(I),'distinct'); finv = @(block) idct2(block.data); D = blockproc(C,[8 8],finv); imshow(D) title('Image reconstructed from 3 DCT coefficients per block') %% % This algorithm code into a local function to go at the % bottom of my app code file, like this: % % function I2 = reconstructImage(I,n) % % Reconstruct the image from n of the DCT coefficients in each 8-by-8 % % block. Select the n coefficients with the largest variance across the % % image. % % % Compute 8-by-8 block DCTs. % f = @(block) dct2(block.data); % A = blockproc(I,[8 8],f); % % % Compute DCT coefficient variances and decide % % which to keep. % B = im2col(A,[8 8],'distinct')'; % vars = var(B); % [~,idx] = sort(vars,'descend'); % keep = idx(1:n); % % % Zero out the DCT coefficients we are not keeping. % B2 = zeros(size(B)); % B2(:,keep) = B(:,keep); % % % Reconstruct image using 8-by-8 block inverse % % DCTs. % C = col2im(B2',[8 8],size(I),'distinct'); % finv = @(block) idct2(block.data); % I2 = blockproc(C,[8 8],finv); % end % % I already have an |update| method in my class, so I can add code to that % method that will compute the reconstructed image and error image. Here's % the revised |update| method: % % function update(app) % recon_image = reconstructImage(app.OriginalImage, ... % app.NumDCTCoefficients); % % diff_image = imabsdiff(app.OriginalImage, recon_image); % % imshow(app.OriginalImage,'Parent',app.OriginalImageAxes); % title(app.OriginalImageAxes,'Original Image'); % % imshow(recon_image,'Parent',app.ReconstructedImageAxes); % title(app.ReconstructedImageAxes,'Reconstructed Image'); % % imshow(diff_image,[],'Parent',app.ErrorImageAxes); % title(app.ErrorImageAxes,'Error Image'); % % imshow(zeros(size(app.OriginalImage)),'Parent',app.MaskAxes); % title(app.MaskAxes,'DCT Coefficient Mask'); % drawnow; % end % % Although I don't have all the interactive behavior wired up yet, and % don't have the DCT coefficient mask visualization done yet, the app runs % and looks a bit more finished than it did before. It now shows the % results for reconstructing the image from 3 DCT coefficients per block. % % <> % % I think it'll take just one more post to finish making the rest of this % app work. ##### SOURCE END ##### 03724e04a81d4ac29734fd49392c5159 -->

Categories: Blogs