We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Shiffman's Image Sharpen issue
Page Index Toggle Pages: 1
Shiffman's Image Sharpen issue (Read 370 times)
Shiffman's Image Sharpen issue
Dec 17th, 2008, 12:00am
 
Hey guys,

So I'm working through Shiffman's book and I'm working through Chapter 15 about Images. I've built from hand a virtual copy of example 15-13 with just a few, purely cosmetic changes.

Please direct your attention to the following code:
Code:

float[][] matrix = { { -1, -1, -1 } ,
{ -1, 9, -1 } ,
{ -1, -1, -1 } } ;


Shiffman asserts that if you change these values all to the average of the parts ( all values changed to 1/9 ) then you'll get a blur effect, but this doesn't seem to be the case. When I make such a change, all I get is a black box. Other changes seem to do either nothing or make a light/screen effect.

How do I achieve a blur effect? Is there something I'm not getting?
Re: Shiffman's Image Sharpen issue
Reply #1 - Dec 17th, 2008, 1:30am
 
I don't know that code specifically, but the theory is correct - a matrix of all 1/9ths would be a blur filter (or a matrix of all 1's, then post-divided by 9).  In implementing it though, make sure you specify 1f/9f (with the f's) to get a floating point result, instead of 1/9 which is an integer result (zero) -- which seems the likely cause of your black result.  hth
Re: Shiffman's Image Sharpen issue
Reply #2 - Dec 17th, 2008, 3:56am
 
davbol wrote on Dec 17th, 2008, 1:30am:
I don't know that code specifically, but the theory is correct - a matrix of all 1/9ths would be a blur filter (or a matrix of all 1's, then post-divided by 9).  In implementing it though, make sure you specify 1f/9f (with the f's) to get a floating point result, instead of 1/9 which is an integer result (zero) -- which seems the likely cause of your black result.  hth



Aha! Science praise you. That trick worked. The book doesn't put down 'f' next to each number in the example. I now have a working model that switches back and forth between sharp/blur on a mouse click.

Quick Question: Is that a casting issue

Edit: Correction, I don't have a working model that changes from blur/sharp on a mouse click! What is the deal After the entire series of code, I added a new function that should change the convolution function's chief input:

(appended to the very bottom of the code)
Code:


void mousePressed() { //This sharpens.

float [][] matrix = { { -1, -1, -1},
{ -1, 9, -1},
{ -1, -1, -1} };
}


The program itself works but clicking the mouse doesn't do anything when it should change into Sharpen mode. What gives?
Re: Shiffman's Image Sharpen issue
Reply #3 - Dec 17th, 2008, 1:30pm
 
Your mousePressed routine defines a matrix double array, which is dropped when the routine ends... Perhaps you wanted to change a global variable or to apply this matrix on the image.
Page Index Toggle Pages: 1