how to assign certain range of pixel values with desired color for classification of image?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponses (2)
Image Analyst
le 16 Fév 2020
Try imoverlay() to overlay your segmented/masked image over your original.
0 commentaires
Rik
le 16 Fév 2020
Modifié(e) : Rik
le 18 Fév 2020
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]);
2 commentaires
Rik
le 18 Fév 2020
L is a 2D logical, so that line sets the third channel (the blue channel) to 1 on every position where L is true. You may need to use 255 instead of 1 by the way.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!