Skip to content

Instantly share code, notes, and snippets.

@dgolden1
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgolden1/8a3b0653cc3731ce85c7 to your computer and use it in GitHub Desktop.
Save dgolden1/8a3b0653cc3731ce85c7 to your computer and use it in GitHub Desktop.
Reproduce Matlab 2014b bug with alpha channel
function matlab_alpha_bug
% Reproduce a bug on Matlab 2014b
% The peppers image will be plotted correctly; coins will not
% Both are plotted correctly in 2014a
% Daniel Golden (dan, followed by cellscope, followed by dot com)
%% Setup
close all;
%% Go
make_figure_with_overlay(imread('peppers.png'));
make_figure_with_overlay(imread('coins.png'));
function make_figure_with_overlay(img)
%% Show original image
figure;
imshow(img, 'InitialMagnification', 'fit');
%% Create alpha info
[X, Y] = meshgrid(1:size(img, 2), 1:size(img, 1));
alpha_data = zeros(size(X));
cx = round(size(img, 2)/2);
cy = round(size(img, 1)/2);
alpha_data(sqrt((X - cx).^2 + (Y - cy).^2) < 100) = 1;
%% Create all red image
red_img = zeros([size(img, 1), size(img, 2), 3]);
red_img(:,:,1) = 1;
%% Overlay mask
hold on;
h = imshow(red_img, 'InitialMagnification', 'fit');
set(h, 'AlphaData', alpha_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment