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

how can i color the particular block of the image?

Asked by pammy on 5 May 2013

m working on gray scale images.. i've extracted a particular block from the code for the above is :

 blockNumber = 1;
 blockrows =2; blockcols = 2;
 [blockcol, blockrow] = ind2sub( [blockcols, blockrows], blockNumber);
 colstart = (blockcol-1) * blockSizeC + 1;
 rowstart = (blockrow - 1) * blockSizeR + 1;
 oneBlock1 = grayImage(rowstart : rowstart + blockSizeR - 1, colstart : colstart + blockSizeC - 1);
 imshow(oneBlock);

i want to color the above block..how can i do so????

 grayImage(rowstart : rowstart + blockSizeR - 1, colstart : colstart + blockSizeC - 1)=0;

the above code color the block with black but it distorts the intensity values.

plz help me to do so..

0 Comments

pammy

Products

No products are associated with this question.

1 Answer

Answer by Iman Ansari on 5 May 2013
Accepted answer

Hi.

clear
grayImage=imread('cameraman.tif');
blockNumber = 34;
blockSizeC=32;
blockSizeR=32;
blockrows =8; blockcols = 8;
[blockrow, blockcol] = ind2sub( [blockcols, blockrows], blockNumber);
colstart = (blockcol-1) * blockSizeC + 1;
rowstart = (blockrow - 1) * blockSizeR + 1;
oneBlock = grayImage(rowstart : rowstart + blockSizeR - 1, colstart : colstart + blockSizeC - 1);
New=cat(3,grayImage,grayImage,grayImage);
New(rowstart : rowstart + blockSizeR - 1, colstart : colstart + blockSizeC - 1,[1 3])=0;
imshow(New);

4 Comments

Iman Ansari on 6 May 2013

I changed it to color Image with:

R=grayImage;
G=grayImage;
B=grayImage;

because R,G and B values are the same, your output image looks graylevel image. R and B components in your block became 0, so your block seems green. Your grayImage didn't changed and in color image (New) the green component is the same as grayImage:

New(:,:,2)==grayImage
Iman Ansari on 6 May 2013

I changed it to color Image with:

R=grayImage;
G=grayImage;
B=grayImage;

because R,G and B value are the same, so your output image looks gray level image. R and B components in your became 0, your block seems green. Your grayImage didn't change and in color image (New) the green component is the same as grayImage:

New(:,:,2)==grayImage
pammy on 7 May 2013

thank you so much

Iman Ansari

Contact us