i have an image where i found out green and i need a code to covert the rest into white

1 vue (au cours des 30 derniers jours)
clc clear all close all p=0; %Tree Crown Detection and Delineation in High Resolution RS Image F=imread('E:\projectimages\imgs\gre
.jpg'); imshow(F); title('Input image'); F=im2double(F); r=F(:,:,1); g=F(:,:,2); b=F(:,:,3); th=acos((0.5*((r-g)+(r-b)))./((sqrt((r-g).^2+(r-b).*(g-b)))+eps)); H=th; H(b>g)=2*pi-H(b>g); H=H/(2*pi); figure,imshow(H); title HUE S=1-3.*(min(min(r,g),b))./(r+g+b+eps); % read an image %Im = imread('E:\projectimages\imgs\gmap1.jpg'); % get the size %[h, w, ~] = size(Im); %figure, imshow(Im) %f = imfreehand; % Then draw the region using imfreehand tool %bw = createMask(f); %outI = bw*I; %numPixelsInsideRegion = sum(outI(:)) figure,imshow(S);
title SATURATION I=(r+g+b)/3; figure,imshow(I);
title INTENSITY hsi=cat(3,H,S,I); figure,imshow(hsi); title HSI
%GAUSSIAN FILTERING h = fspecial('gaussian', [11,11], 2); I1 = imfilter(hsi,h); figure,imshow(I1); title('STAGE-A Filtered image');
%STAGE - C HE=H*2*pi; HE=histeq(HE); figure,imshow(HE); title HISTOGRAMEQUALIZATION; HE=HE/(2*pi); SE=histeq(S); figure,imshow(SE); title HISTOGRAMEQUALIZATION; IE=histeq(I); figure,imshow(IE); title HISTOGRAMEQUALIZATION; D = (SE-IE); figure,imshow(D); title('STAGE-D Normalized difference image'); [m,n] = size(SE); E = zeros(m,n); for i = 1:m for j = 1:n if D(i,j) > 0 E(i,j) = 1;
else
E(i,j) = 0;
end
end
end
figure,imshow(E);
title('STAGE-E CANDITATE REGIONS');
% cc1 = bwconncomp(E); cc1.NumObjects % remove all object containing fewer than 30 pixels %BW4 = bwareaopen(BW4,30); % fill a gap in the pen's cap %se = strel('disk',2); %BW4 = imclose(BW4,se); % fill any holes, so that regionprops can be used to estimate % the area enclosed by each of the boundaries
stats = regionprops(cc1, 'Area'); idx1 = find([stats.Area] > 1000); BW4 = ismember(labelmatrix(cc1), idx1);
%remove all object containing fewer than 30 pixels %BW4 = bwareaopen(BW4,30); % fill a gap in the pen's cap %se = strel('disk',2); %BW4 = imclose(BW4,se); % fill any holes, so that regionprops can be used to estimate % the area enclosed by each of the boundaries BW4 = imfill(BW4,'holes'); imshow(BW4); B = bwboundaries(BW4); imshow(BW4) se = strel('disk',2); closeBW = imclose(BW4,se); figure, imshow(closeBW) figure,imshow(BW4); [rows columns numberOfColorBands] = size(BW4); numberOfBlackPixels = sum(sum(BW4 == 0)); numberOfWhitePixels = sum(sum(BW4)); totalNumberOfPixels = rows * columns; percentBlackPixels = 100.0 * numberOfBlackPixels totalNumberOfPixels; percentWhitePixels = 100.0 * numberOfWhitePixels totalNumberOfPixels; p= numberOfWhitePixels / (numberOfBlackPixels+numberOfWhitePixels) ;
message = sprintf('Done!\nTotal number of pixels = %d\nBlack pixels = %d = %.1f%%\nWhite pixels = %d = %.1f%%', ...
totalNumberOfPixels, numberOfBlackPixels, percentBlackPixels, ...
numberOfWhitePixels, percentWhitePixels,'p= %d');
msgbox(message);
%
title('TREE');
G = edge(BW4,'sobel'); figure,imshow(G); title('CROWNS'); [a,b1] = find(G==1); figure,imshow(F);hold on; for i =1:length(a) plot(b1(i),a(i), 'r-');hold on; end title('Delineation result');

Réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by