how to assign certain range of pixel values with desired color for classification of image?

1 次查看(过去 30 天)
I used GLCM to obtain properties of image. I have displayed different properties taking effects on input image .
for a start, I have taken energy image ..now i am trying to classify the image using thresholding method.
the water body in my image can be detected and i noted the minimum and maximum pixelvalue of that region using image viewer app in matlab
i wanted to assign blue color to that specific range of pixel values. i have written sample code how i want to classify
how many changes i try to make also ,somehow it is either displaying as water body (only) in grey scale or the entire image is returning into blue
clc;
clear all;
close all;
Image=imread('D:/project/myfeatures/energystack.tif');
blue(:,:,3)=zeros(size(Image));
for i=1:size(Image,1)
for j=1:size(Image,2)
pixel=Image(i,j);
if (pixel>= 40&&pixel<= 140)
blue(:,:,3)=Image;
end
end
end
figure
imshow(blue(:,:,3))
any type of suggestion or guidance is welcome.thank you!

回答(2 个)

Image Analyst
Image Analyst 2020-2-16
Try imoverlay() to overlay your segmented/masked image over your original.

Rik
Rik 2020-2-16
编辑:Rik 2020-2-18
What you need to do is replicate your grayscale image to three channels to make it an RGB image. Then you can modify the the color for your specific pixels.
%get an example image
defimage = pow2(get(0,'DefaultImageCData'),47);
IM = bitshift(defimage,-37);IM = fix(IM);
IM = bitand(IM,31);IM = IM/max(IM(:));
I=uint8(255*IM);
L=I<100;
I(L)=0;
I=repmat(I,1,1,3);
[ind1,ind2]=find(L);
ind3=3*ones(size(ind1));
ind=sub2ind(size(I),ind1,ind2,ind3);
I(ind)=255;
%an alternative is to extend the logical mask to 3D:
%L3D=L;L3D(1,1,3)=0;L3D=L3D(:,:,[3 2 1]);
%I(L3D)=255;
figure(1),clf(1)
subplot(1,3,1)
imshow(IM),title('original image')
subplot(1,3,2)
imshow(L),title('mask')
subplot(1,3,3)
imshow(I),title('modified image')
And as Image Analyst suggests below: all code from I(L)=0; until the figure creation can be replaced by this:
I=imoverlay(I,L,[0 0 1]);

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by