Brian's Latest Blog Entries:

How to Make a Borderless Subplot of Images in MATLAB

Friday, January 27th, 2012

Let’s say that you have a set of images that you want to tile using imshow() and subplot() in a MATLAB figure. By default, both functions add a padded space around the images to separate them, as this example shows:


I1 = zeros(500,'uint8');
I2 = zeros(500,'uint8')+127;
I3 = zeros(500,'uint8')+255;

figure
subplot(1,3,1), imshow(I1);
subplot(1,3,2), imshow(I2);
subplot(1,3,3), imshow(I3);

Result:

However, what if you want to tile the images without any space between them? The imshow() function does have a property to remove the border around a displayed image, by using imshow(I, ‘border’, ‘tight’). This is fine when only one image is being displayed, but subplot() itself adds additional spacing between images. Removing this space is not straightforward, but a gap-less subplot grid can be constructed by using the following function in place of subplot():


function subplottight(n,m,i)
    [c,r] = ind2sub([m n], i);
    subplot(n,m,i, 'Position', [(c-1)/m, 1-(r)/n, 1/m, 1/n])

By using this function, a completely borderless subplot of images can be constructed as follows:


I1 = zeros(500,'uint8');
I2 = zeros(500,'uint8')+127;
I3 = zeros(500,'uint8')+255;

figure
subplottight(1,3,1), imshow(I1, 'border', 'tight');
subplottight(1,3,2), imshow(I2, 'border', 'tight');
subplottight(1,3,3), imshow(I3, 'border', 'tight');

Result:

How to Add the arg max and arg min Functions to Lyx

Sunday, October 30th, 2011

The arg max and arg min functions are not standard as math functions in LaTeX. As a result, they are not straightforward to use in Lyx either. However, it is quite simple to do so:

  1. Add the following code to the LaTeX preamble in Lyx (Document > Settings > LaTeX Preamble):

    \usepackage{amsmath}
    \DeclareMathOperator*{\argmax}{arg\,max}
    \DeclareMathOperator*{\argmin}{arg\,min}
  2. When you create a new math field in Lyx, simply type \argmax or \argmin. You can follow it by an underscore if you need text below the arg max or arg min functions. This text will be centered across all six letters.

It’s that simple!

How to Use a New Latex Class in Lyx

Monday, August 1st, 2011

Let’s say we have a custom new Latex class called “newclass.cls” which we want to be able to use with Lyx under Windows.

  1. Copy the new Latex class file “newclass.cls” into the MikTeX directory within your user settings folder like so: C:\Users\UserName\AppData\Roaming\MiKTeX\2.8\tex\latex\newclass\newclass.cls. Remember to replace UserName with your own Windows user name.
  2. Update the MikTeX list of classes by clicking the Windows Start button and typing cmd into the search box. When the black command line window displays, type texhash and hit Enter.
  3. Next we need to create a layout file for Lyx to work with. This file contains instructions on how to roughly format a document when displayed within the Lyx program itself. More importantly, the layout file points to the Latex class for generating the final output. It is helpful to start by just modifying an existing layout file which is similar in purpose to the Latex class we are trying to add. For example, if our new Latex class is a template for an article, we might want to start by copying article.layout from C:\Program Files (x86)\LyX20\Resources\layouts and pasting it into C:\Users\UserName\AppData\Roaming\LyX2.0\layouts. Rename the file to match your class name, say, “newclass.layout”
  4. Open up your new layout file, and look at the second line. Replace it with:
    # \DeclareLaTeXClass[newclass]{Title of Class}
    Enter your class name within the [] brackets, and enter whatever descriptive name you want to call the class within the {} braces.
  5. Open Lyx, and click Tools > Reconfigure. Restart the Lyx program when it prompts you to do so.

That’s it! When you start a new document in Lyx, your new class should appear within the drop-down box for Document Class in the Document Settings window (Document > Settings).

Tested with Lyx 2.0 and MikTeX 2.8 under Windows 7.

Solution: Individual Stats Missing using WordPress Stats

Thursday, June 9th, 2011

Around the time that I upgraded this blog to WordPress 3.1.3 with the WordPress.com Stats Plugin version 1.8.1, I began noticing that I could no longer view the stats graph for individual pages properly. My overall site stats still displayed, such as the total Views per day graph of my site, the Top Posts & Pages with correct view counts, etc.

However, when I clicked the small graph icon to view the stats graph for individual posts, I would get a blank graph and the error message “We don’t have that post on record yet” followed by the post id. Similarly, when I logged into wordpress.com to check my blog stats using their interface, the title for the posts would be missing (it would only show the post id followed by “loading title”) and trying to view the stats for individual posts would result in a 403 error.

Almost coincidentally, I was browsing through some of my site logs and noticed a few requests for a file, “xmlrpc.php” in my root directory. I noticed requests for this file coincided with my attempts to view individual stats. As it turns out, xmlrpc.php is a WordPress file found in the main WordPress directory, and is used for remote posting, pingbacks, and trackbacks. Apparently, it is also used to read post data for WordPress’s stat system. The problem is, the stats system was looking for xmlrpc.php in the root directory of my site, but my blog resides in a subdirectory on my server. Since the file appeared to be missing, the correct data could not load, and individual stats would not display.

To solve this problem, I simply copied xmlrpc.php from my WordPress subdirectory into the root directory of my site. I only needed to edit one line, the include statement for wp-load.php. I adjusted the path so it pointed to the actual wp-load.php in my WordPress subdirectory. After doing this, individual stat graphs worked perfectly!

Instead of this method, it might also be possible to use an .htaccess edit to redirect requests for the xmlrpc.php file, but I did not try this. I hope this information might help someone who stores their WordPress blog in a subdirectory and has experienced this same problem. I was unable to find any information about something like this on Google or the WordPress forums.

More information on xmlrpc.php:
http://codex.wordpress.org/XML-RPC_Support
http://digwp.com/2009/06/xmlrpc-php-security/

How to Add a Double Outline Style Around Text in Photoshop

Monday, June 6th, 2011

The easiest way to add a single outline to a text layer in Adobe Photoshop is by applying a Stroke to the text in the Layer Style options. But since only one stroke per layer is allowed, how can you add a double outline, or a double stroke? It turns out you can get nearly the same effect by clever use of the Outer Glow style, in addition to the Stroke style. To add a double outline to a text layer, do the following:

  1. Create your initial text layer. I used 48pt Arial for my example.
  2. Create the first outline. Go to Layer > Layer Style > Stroke. Select your desired size and color. Make sure the Position is Outside, Blend Mode is Normal, and Opacity is 100%.

  3. Now add the Outer Glow effect. Click Outer Glow in the Styles list in the Layer Style window. Set the Blend Mode to Normal and Opacity to 100%. Select the color you want for the second outline.
  4. Adjust the Size to any desired number, but make sure it is larger than your previous Stroke size.
  5. Reduce the Range setting to a low value, somewhere between 1%-5%. A lower value will make the second outline appear more crisp, while a higher value will blur the outer edges slightly.

When the proper settings are adjusted, the Outer Glow acts as a second stroke. You now have a double outline around your text!

Page 1 of 512345

Copyright © 2011 by Brian D'Alessandro | Home | Contact | Privacy Policy