How to overlap Jpeg images in MatLab

1 view (last 30 days)
Thomas P
Thomas P on 1 Apr 2015
Edited: Thomas P on 1 Apr 2015
Is it possible to use multiple jpgs in Matlab using something like the transparency? I am planning on making a battleship- like game on Matlab for a project. I want to use X's on the ships. I have a picture of the ships; however, I cannot find a way to take a X jpg and use it in the foreground. Please Help! Please provide code if possible. I understand so far
imread('x.jpg') %Background image
imshow('x.jpg')
From here, I do not know how to use transparency functions nor creating another jpg on top.

Answers (1)

Joep
Joep on 1 Apr 2015
Edited: Joep on 1 Apr 2015
rgb = imread('peppers.png');
imshow(rgb);
I = rgb2gray(rgb);
hold on
% Save the handle for later use
h = imshow(I);
hold off
[M,N]=size(I);
%Create matrix for transparency
alpha=zeros(M,N);
%Matrix part with transparency
alpha(1:100,1:N)=0.5;
set(h, 'AlphaData', alpha);

Categories

Find more on Display Image in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!