Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: CData and NaN

Subject: CData and NaN

From: Dilshatbek Djumanov

Date: 13 Dec, 2007 02:57:37

Message: 1 of 6

Hi, sorry if the question is repeated.
I am trying to make an icon on a button to be partially
transparrent.
It kind a works with 2d array, but with 3d (кпи) does not.
Here is my code where I cannot to change 0s into NaN. It
just wouldn't.
Please help. Thank you.

function setPicture(hObject, iconName)
    %insert graphic to button
    [a, map, alpha] = imread(iconName);
    %cut the size into 16x16
    [r,c,d]=size(a);
    x=ceil(r/16);
    y=ceil(c/16);
    g=a(1:x:end,1:y:end,:);
    %change 0s to NaN
      %g(g==0)=NaN; this did not work either
    %MANUAL CHANGE DOESNOT WORK as well
    % am I missing anything
    [r,c,d]=size(g);
    for ri=1:r
        for ci=1:c
            if (alpha(ri,ci,1)==0)
                %I checked when alpha is 0 then tis pixel
                %should be transparent
                for ii=1:d g(ri,ci,ii) = NaN; end;
            end;
        end;
    end;
    set(hObject,'CData', g)

Subject: CData and NaN

From: Bruno Luong

Date: 13 Dec, 2007 05:57:26

Message: 2 of 6

"Dilshatbek Djumanov" <d.djumanov@ukbritannia.co.uk> wrote
in message <fjq730$890$1@fred.mathworks.com>...
> Here is my code where I cannot to change 0s into NaN. It
> just wouldn't.

What is the class of your image? "Not a Number" (NaN) is
still a float and it's surely Not an Integer.;-)

Use CLASS() to report the class of your image.

Bruno


Subject: CData and NaN

From: Dilshatbek Djumanov

Date: 16 Dec, 2007 22:43:14

Message: 3 of 6

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fjqhk6$mg0$1@fred.mathworks.com>...
> "Dilshatbek Djumanov" <d.djumanov@ukbritannia.co.uk> wrote
> in message <fjq730$890$1@fred.mathworks.com>...
> > Here is my code where I cannot to change 0s into NaN.
It
> > just wouldn't.
>
> What is the class of your image? "Not a Number" (NaN) is
> still a float and it's surely Not an Integer.;-)
>
> Use CLASS() to report the class of your image.
>
> Bruno
>
>
Thanks for the reply
not sure what you asked for but I gues this

K>> iconName
iconName = open1.png

K>> class(iconName)
ans = char

K>> class(a)
ans = uint8

K>> class(map)
ans = double

K>> class(alpha)
ans = uint8

K>> class(NaN)
ans = double

"a" is a (16,16,3) array, I am trying to set to NaN where a
(ii,jj,:)==0
all my png files are 16 by 16 pixels.
example

K>> a

a(:,:,1) =

  Columns 1 through 11

    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 42 42 42 42
  255 255 255 255 255 0 0 0 56 43 16
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 255 255 249
  255 255 255 255 255 255 255 255 255 255 42
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 253 255 255
  255 255 255 255 255 255 253 255 255 255 255
  255 253 255 251 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 255 255 255
  255 255 255 255 255 255 255 255 0 0 0
  255 255 255 255 0 0 0 0 0 0 0

  Columns 12 through 16

    0 0 0 0 0
    0 0 0 0 0
   42 65 0 0 0
   40 85 67 0 0
  118 119 58 0 0
  146 146 112 42 255
   42 146 42 255 255
  255 42 255 255 255
  255 255 255 255 255
  255 255 255 255 0
  255 255 255 255 0
  255 255 255 0 0
  255 255 0 0 0
  255 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0


a(:,:,2) =

  Columns 1 through 11

    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 154 154 154 154
  204 204 204 204 204 0 0 0 121 131 134
  204 255 255 255 255 204 204 204 204 204 204
  204 255 255 255 255 255 255 255 255 255 251
  204 253 204 204 204 204 204 204 204 204 154
  204 240 204 255 255 255 255 255 255 255 255
  204 227 204 255 255 255 255 255 252 255 255
  204 216 204 255 255 255 252 255 255 255 255
  204 203 204 250 255 255 255 255 255 255 255
  204 204 255 255 249 249 249 249 249 249 249
  204 204 255 246 240 241 241 241 241 240 241
  204 204 255 233 232 232 232 233 234 243 245
  204 204 255 224 231 233 235 235 204 204 204
  204 204 235 227 204 204 204 204 0 0 0
  204 204 204 204 0 0 0 0 0 0 0

  Columns 12 through 16

    0 0 0 0 0
    0 0 0 0 0
  154 144 0 0 0
  137 186 142 0 0
  174 215 149 0 0
  247 247 215 154 204
  154 247 154 255 204
  255 154 255 255 204
  255 233 254 255 204
  255 233 255 204 0
  250 234 248 204 0
  242 243 204 0 0
  247 204 0 0 0
  204 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0


a(:,:,3) =

  Columns 1 through 11

    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 19 19 19 19
    0 0 0 0 0 0 0 0 56 42 8
    0 173 173 166 182 0 0 0 0 0 0
    0 163 148 152 149 169 188 176 170 164 154
    0 156 0 0 0 0 0 0 0 0 19
    0 142 0 207 207 207 207 207 207 207 208
    0 133 0 207 207 207 207 207 223 210 208
    0 124 0 207 207 207 198 198 177 174 175
    0 104 0 201 158 156 154 152 154 154 154
    0 0 207 207 141 146 146 146 146 146 146
    0 0 207 154 136 139 139 139 139 139 139
    0 0 207 127 130 130 131 131 134 138 135
    0 0 207 118 127 127 130 126 0 0 0
    0 0 136 108 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0

  Columns 12 through 16

    0 0 0 0 0
    0 0 0 0 0
   19 61 0 0 0
   14 38 66 0 0
   71 69 47 0 0
   94 94 70 19 0
   19 94 19 241 0
  208 19 241 241 0
  177 146 214 202 0
  155 135 202 0 0
  146 135 163 0 0
  141 136 0 0 0
  134 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0

thanks for help

Subject: CData and NaN

From: Dilshatbek Djumanov

Date: 17 Dec, 2007 16:55:51

Message: 4 of 6

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fjqhk6$mg0$1@fred.mathworks.com>...
> "Dilshatbek Djumanov" <d.djumanov@ukbritannia.co.uk> wrote
> in message <fjq730$890$1@fred.mathworks.com>...
> > Here is my code where I cannot to change 0s into NaN.
It
> > just wouldn't.
>
> What is the class of your image? "Not a Number" (NaN) is
> still a float and it's surely Not an Integer.;-)
>
> Use CLASS() to report the class of your image.
>
> Bruno
>
>

Hi
solution found by wierd workaround

clc;
clear;
%insert graphic to button
[a, map, alpha] = imread('open1.png');
[r,c,d]=size(a);
x=ceil(r/16);
y=ceil(c/16);
g=a(1:x:end,1:y:end,:);
[r,c,d]=size(g);
gg=NaN(r,c,d);
for ri=1:r
    for ci=1:c
        for ii=1:3
            if (alpha(ri,ci)>0)
                gg(ri,ci,ii) = (g(ri,ci,ii));
            end;
        end;
    end;
end;
ggg=gg/255
h = uicontrol(...
    'Style', 'pushbutton', ...
    'String', '',...
    'Position', [20 150 25 25]);
set(h,'CData', ggg );



Subject: CData and NaN

From: Stefan Siegel

Date: 20 Feb, 2008 17:02:04

Message: 5 of 6

Thank you for your solution for the transparency!
I didn't know that I could use NaN as replacement for the alpha!

In case someone else stumbles across this thread:
A possible shorter version of the code would be something
like the following:

[icon, temp, iconAlpha] = imread('icon.png');
icon = double(icon)/255;
icon(iconAlpha < 1) = NaN;

Subject: CData and NaN

From: Daniel

Date: 18 Jun, 2008 21:58:01

Message: 6 of 6

Wow, thanks for that last post. It works beautifully.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
transparency Stefan Siegel 20 Feb, 2008 11:56:45
transparent Stefan Siegel 20 Feb, 2008 11:56:45
opaque Stefan Siegel 20 Feb, 2008 11:56:45
translucent Stefan Siegel 20 Feb, 2008 11:56:45
icon Dilshat 12 Dec, 2007 22:03:41
nan Dilshat 12 Dec, 2007 22:03:40
cdata Dilshat 12 Dec, 2007 22:03:40
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics