Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Inserting a .jpg or .ico image on a pushbutton

Subject: Inserting a .jpg or .ico image on a pushbutton

From: Camille Couzi

Date: 15 Nov, 2010 15:31:06

Message: 1 of 4

Hi!
I would like to put an image on a pushbutton. I know that I can insert it with the CData propertie, but this is for matrix (20,20,3) (if we want 20 pixels). Is there a way to insert a .jpg image, or a .ico ? Or is there some program which can convert my .jpg in a 20*20*3 matrix?
thanks!!

Subject: Inserting a .jpg or .ico image on a pushbutton

From: Sean de

Date: 15 Nov, 2010 15:54:04

Message: 2 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <ibrjnq$i65$1@fred.mathworks.com>...
> Hi!
> I would like to put an image on a pushbutton. I know that I can insert it with the CData propertie, but this is for matrix (20,20,3) (if we want 20 pixels). Is there a way to insert a .jpg image, or a .ico ? Or is there some program which can convert my .jpg in a 20*20*3 matrix?
> thanks!!

Just crop and downsample your matrix so it is 20x20x3.

if I = 400x400x3:
new_Image = I(1:20:end,1:20:end,:);

Subject: Inserting a .jpg or .ico image on a pushbutton

From: Camille Couzi

Date: 15 Nov, 2010 16:07:04

Message: 3 of 4

Hi Sean De,
yes but I want to insert an image, for example I would like to put and image, like for example this one:

http://www.google.cl/imgres?imgurl=http://4.bp.blogspot.com/_0eDJLgoRLRQ/ScK1qEjD-FI/AAAAAAAAA-c/io-CLSkEtuI/s400/felix%2Bthe%2Bcat.jpg&imgrefurl=http://cutecartooncharacters.blogspot.com/2009/03/felix-cat-from-felix-cat.html&usg=__KTnLqHJAFZxLZOoQolhLGXWFDJk=&h=400&w=359&sz=21&hl=es&start=0&zoom=1&tbnid=6Ad-5dtau633FM:&tbnh=112&tbnw=105&prev=/images%3Fq%3Dcat%26hl%3Des%26biw%3D1920%26bih%3D895%26gbv%3D2%26tbs%3Disch:1&itbs=1&iact=rc&dur=471&ei=H1rhTPTNDoS0lQe858iXDQ&oei=H1rhTPTNDoS0lQe858iXDQ&esq=1&page=1&ndsp=75&ved=1t:429,r:0,s:0&tx=72&ty=59

Let's say this image is 60*80 pixels.
how do I load it in matlab, and then simplify the pixels so that I put it in 20*20, and I get the R G B colors to make my 20*20*3 matrix for CData?

Thanks for your help.

Subject: Inserting a .jpg or .ico image on a pushbutton

From: Sean de

Date: 15 Nov, 2010 16:20:23

Message: 4 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <ibrlr8$fsp$1@fred.mathworks.com>...
> Hi Sean De,
> yes but I want to insert an image, for example I would like to put and image, like for example this one:
>
> http://www.google.cl/imgres?imgurl=http://4.bp.blogspot.com/_0eDJLgoRLRQ/ScK1qEjD-FI/AAAAAAAAA-c/io-CLSkEtuI/s400/felix%2Bthe%2Bcat.jpg&imgrefurl=http://cutecartooncharacters.blogspot.com/2009/03/felix-cat-from-felix-cat.html&usg=__KTnLqHJAFZxLZOoQolhLGXWFDJk=&h=400&w=359&sz=21&hl=es&start=0&zoom=1&tbnid=6Ad-5dtau633FM:&tbnh=112&tbnw=105&prev=/images%3Fq%3Dcat%26hl%3Des%26biw%3D1920%26bih%3D895%26gbv%3D2%26tbs%3Disch:1&itbs=1&iact=rc&dur=471&ei=H1rhTPTNDoS0lQe858iXDQ&oei=H1rhTPTNDoS0lQe858iXDQ&esq=1&page=1&ndsp=75&ved=1t:429,r:0,s:0&tx=72&ty=59
>
> Let's say this image is 60*80 pixels.
> how do I load it in matlab, and then simplify the pixels so that I put it in 20*20, and I get the R G B colors to make my 20*20*3 matrix for CData?
>
> Thanks for your help.

For a completely automated way just do this:

I saved it as 'felix.jpg':

%%
I = imread('felix.jpg');
spa = ceil(size(I)/20);
Ismall = I(1:spa(1):end,1:spa(2):end,1:spa(3):end);

You could also do something that isolates the parts you want so the downsampled image keeps more data:
%% This will isolate the part of that you want:
Ikeep = (255-I(:,:,1))>10;
[ii jj] = find(Ikeep);
mxs = max([ii jj]);
mns = min([ii jj]);

I = I(mns(1):mxs(1),mns(2):mxs(2),:);

%% Then run the original two lines of code

Tags for this Thread

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.

Contact us