Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:37:06+00:00 2026-06-09T16:37:06+00:00

Problem : The image loses its transparency when plot using surf I have already

  • 0

Problem : The image loses its transparency when plot using surf

I have already figured out how to create a png file with a transparent background as described in numerous other threads.here

However, when plot using surf.m, the image is not transparent

Here is the code that I have so far:

img = imread('image.png');

A1 = ones(size(img));A2 = ones(size(img));A3 = ones(size(img));
A1(img(:,:,1)==0)=0;A2(img(:,:,2)==0)=0;A3(img(:,:,3)==0)=0;

A = A1+A2+A3;
A= A(:,:,1);

imwrite(img,'test.png','alpha',A);
[img,map,alpha] = imread('test.png');

ximage = [-.5,.5;-.5,.5];
yimage = [0,0;0,0];
zimage = [.5,.5;-.5,-.5];

surf(ximage,yimage,zimage,'Cdata',img,'Facecolor','texturemap','Edgecolor','none','alphadata',alpha);
axis vis3d

The code converts image.png (blue square) to a test.png with a transparent background (get rid of the black background). test.png is then used to generate a surf plot which turns out to be not transparent. Any idea what I am doing wrong?

blue square with black background - need to plot this as a 3D slice without the black background

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:37:07+00:00Added an answer on June 9, 2026 at 4:37 pm

    There is a function called alpha in MATLAB which sets transparency for the objects in current axes. I suggest to change the variable named alpha to another name by replacing the following line

    [img,map,alpha] = imread('test.png');
    

    to

    [img,map,alphaChannel] = imread('test.png');
    

    Now, after running surf, you can set the transparency for your plot through alpha function.

    Using alpha function

    surf(ximage,yimage,zimage,'Cdata',img,'Facecolor','texturemap','Edgecolor', ...
                              'none','alphadata',alpha);
    alpha(0.5); %# line added
    axis vis3d
    

    Using surf function

    If you want to set the transparency through the surf function, you need to add 'FaceAlpha' parameter:

    surf(ximage,yimage,zimage,'Cdata',img,'Facecolor','texturemap','Edgecolor', ... 
                              'none','AlphaData',alphaChannel,'FaceAlpha',0.5);
    

    Result

    Image obtained through through any example above

    More information about alpha and surf functions.


    Setting a matrix transparency

    But those functions above sets the transparency for the entire plot. If you want to set your original matrix of transparency, you need to pass 'FaceAlpha','texture' parameter to surf:

    handler = surf( ximage , yimage , zimage , 'Cdata', img , ...
        'FaceColor','texturemap',                             ...
        'EdgeColor','none',                                   ... 
        'FaceAlpha','texture',                                ...
        'AlphaData', alphaChannel);
    axis vis3d
    

    Result

    Image obtained by setting 'FaceAlpha'

    More details. Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with UIButton image if I set its imageView contentMode to
i have problem with image vertical-align in div .img_thumb { float: left; height: 120px;
i have created one image but problem is that when i save image from
I have a problem with loading image with java 2ME. I have a image
I have a problem with an image preview that comes up when you hover
I have a problem with drawing image. How I can draw image in precision
I have a problem in the following code: //quesry the db for image information
I have an image upload form <% using (Html.BeginForm(PictureValidateAndSave, UserGallery, new {}, FormMethod.Post, new
I have an odd problem. I am using an AQGridView which has a method
I'm having a problem with image scaling. When I use the following code to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.