TST
TST

Reputation: 13

Coloring an image in matlab

I would like to know how to color a rectangle created in matlab itself by the following code:

rectangle = 255*ones(100,100);
line1 = zeros(1,70);
line2 = zeros(1,40);
rectangle(1,1:70) = line1;
rectangle(40,1:70) = line1;
rectangle(1:40,1) = line2;
rectangle(1:40,70) = line2;
figure(1)
imshow(rectangle);

Thanks for the help!

Upvotes: 1

Views: 127

Answers (1)

anon01
anon01

Reputation: 11181

I'd suggest looking into matlabs built in graphics objects rather than making them from scratch; this will save you significant time. This is a different method though - you are not manipulating matrices, but using built in objects that matlab has already specified. You can look here for more info, but here's an example that might be relevant:

figure;
hold all;
xlim([0,1]);
ylim([0,1]);
set(gca,'visible','off');
rectangle('Position',[0,0,.5,.5],'FaceColor',[1,0,0]);
rectangle('Position',[.5,.5,.2,.2],'FaceColor',[0,0,1],'EdgeColor',[0,0,0],'Linewidth',4,'Linestyle','--');

resulting picture:

enter image description here

Upvotes: 1

Related Questions