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)
"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.;-)
"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
"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 );
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.