how to change pixels value of a color image according to thresholding?

2 ビュー (過去 30 日間)
kristie bell
kristie bell 2015 年 3 月 23 日
編集済み: kristie bell 2015 年 3 月 23 日
Hi guys,
I needed some help with my current code. What i wanted to do is to read in a colour image, change it to grayscale and enhance the color using thresholding (like pixel values of 4 i want it to be enhanced to 10 etc). Then i wanted to map back to the color image.
I understand that i am currently using 0-255 threshold values on a grayscale level, but if i were to manipulate the values on pixels(:,:,1), how can i use something that is equivalent?
I could not get back the color image.
May i know how could this be done? Any help will be appreciated! Thanks!
below is my code:
%color image pixels = imread('new_matched_area.jpg');
% allocate space for image %image_2 = zeros(size(pixels)); image_1 = zeros(size(pixels));
image_thresholded = pixels(:,:,1);
image_2 = rgb2gray(pixels);
tic % perform thresholding by logical indexing %image_thresholded = image_2; image_thresholded(image_2>250) = 256; image_thresholded(image_2>=100 & image_2<=110) = 155; image_thresholded(image_2>=10 & image_2<11) = 130; image_thresholded(image_2>=9 & image_2<10) = 120; image_thresholded(image_2>=8 & image_2<9) = 110; image_thresholded(image_2>=7 & image_2<8) = 100; image_thresholded(image_2>=6 & image_2<7) = 70; image_thresholded(image_2>=5 & image_2<6) = 60; image_thresholded(image_2>=4 & image_2<5) = 40; image_thresholded(image_2>=3 & image_2<4) = 10; image_thresholded(image_2<2) = 5; image_thresholded = image_1; %image_thresholded(image_2<0.5) = 0; image_2 = cat (3, pixels(:,:,1) +pixels(:,:,2) +pixels(:,:,3));
toc % display result figure(1), imshow(image_1) figure(2),imshow(pixels) figure(3),imshow(image_2) title('thresholded image')

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by