フィルターのクリア

to extract pixel value from difference of gaussian filter

2 ビュー (過去 30 日間)
RANJITHA H V
RANJITHA H V 2015 年 5 月 9 日
回答済み: Image Analyst 2015 年 5 月 9 日
% Computes a Difference oOf Gaussians filter. clc; % Clear the command window. close all; % Close all figures (except those of imtool.) clear; % Erase all existing variables. workspace; % Make sure the workspace panel is showing. format longg; format compact; fontSize = 20;
I=imread('1.jpg'); grayImage = rgb2gray(I); % Get the dimensions of the image. % numberOfColorBands should be = 1. [rows columns numberOfColorBands] = size(grayImage); % Display the original gray scale image. subplot(2, 2, 1); imshow(grayImage, []); title('Original Grayscale Image', 'FontSize', fontSize); % Enlarge figure to full screen. set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Give a name to the title bar. set(gcf,'name','graphs','numbertitle','off')
% Let's compute and display the histogram. [pixelCount grayLevels] = imhist(grayImage); subplot(2, 2, 2); bar(pixelCount); grid on; title('Histogram of Original Image', 'FontSize', fontSize); xlim([0 grayLevels(end)]); % Scale x axis manually.
gaussian1 = fspecial('Gaussian', 21, 15); gaussian2 = fspecial('Gaussian', 21, 20); dog = gaussian1 - gaussian2; dogFilterImage = conv2(double(grayImage), dog, 'same'); subplot(2, 2, 3); imshow(dogFilterImage, []); title('DOG Filtered Image', 'FontSize', fontSize); imtool(dogFilterImage);
% Let's compute and display the histogram. [pixelCount grayLevels] = hist(dogFilterImage(:)); subplot(2, 2, 4); bar(grayLevels, pixelCount); grid on; title('Histogram of DOG Filtered Image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually. yRange = ylim; % Calculate the mean gray level meanGL = sum(pixelCount .* grayLevels) / sum(pixelCount); meanBinHeight = mean(pixelCount); line([meanGL meanGL], yRange); message = sprintf('The mean gray level is %6.2f', meanGL); text(meanGL+5, 0.8*yRange(2), message); message = sprintf('Done!\nThe mean gray level is %6.2f\nThe mean binheight = %.2f', ... meanGL, meanBinHeight); msgbox(message);
In the above program, i am getting negative values for some pixels(pixels of my interest) in difference of Gaussian filter for which i plotted imtool and positive values for remaining pixels. please help me in converting this image to binary image. i want negative valued pixels to be white(255) and remaining all pixels to black(0).

回答 (1 件)

Image Analyst
Image Analyst 2015 年 5 月 9 日
Of course there will be negative values - a DoG filter is an edge detection filter.
If you want negative values to be white and zero and positive values to be black, you can do this
binaryImage = dogImage < 0; % Logical image -- 0 and 1 (false and true)
If you want an uint8 integer image, multiply by 255
image255 = uint8(255 * binaryImage);
By the way, I attached my demo of a dog filter.

カテゴリ

Help Center および File ExchangeCamera Calibration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by