matlab - How do I convert the whole image to grayscale except for a sub image which should be in color? -


i have image , subimage cropped out of original image.

here's code have written far:

val1 = imread(img); val2 = imread(img_w); gray1 = rgb2gray(val1);%grayscaling both images gray2 = rgb2gray(val2); matchingval = normxcorr2(gray1,gray2);%normalized cross correlation  [max_c,imax]=max(abs(matchingval(:))); 

after stuck. have no idea how change whole image grayscale except sub image should in color.

how do this?

thank you.

if know coordinates image, can use rgb2gray on section of interest.

for instance, tried on image now:

im(500:1045,500:1200,1)=rgb2gray(im(500:1045,500:1200,1:3)); im(500:1045,500:1200,2)=rgb2gray(im(500:1045,500:1200,1:3)); im(500:1045,500:1200,3)=rgb2gray(im(500:1045,500:1200,1:3)); took rows (500 1045), columns (500 1200), , rgb depth (1 3) of image , applied rgb2gray function that. did 3 times output of rgb2gray 2d matrix , color image 3d matrix, needed change layer layer.

this worked me, making part of image gray leaving rest in color.

the issue might have though this, color image 3 dimensions while gray scale need 2 dimensions. combining them means gray scale must in 3d matrix.

depending on want do, technique may or may not help.


Popular posts from this blog