I have one image with a circle, outside the circunference the color are black inside the circle the color before convert to grayscale, is gray, how can apply after normalize de image apply a mask who convert a the background in same color (gray). https://www.dropbox.com/sc/zfp80poi11m8q55/lnRX67BT4L exemple image A and B
MATLAB: One image 2 diferent colors ,
background normalizationpreprossesing image
Related Solutions
That has nothing to do with log. That's a standard Laplacian high boost filter. Here, try this:
grayImage = imread('peppers.png');imshow(grayImage);% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);if numberOfColorChannels > 1 % It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage); % ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end% Display the image.
subplot(2, 1, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');h = [-1 -1 -1; -1 9 -1; -1 -1 -1]filteredImage = conv2(double(grayImage), h, 'same');% Display the image.subplot(2, 1, 2);imshow(filteredImage, [0, 255]);title('Filtered Image', 'FontSize', fontSize, 'Interpreter', 'None');
Christine
you only plot 4 images, yet in the command subplot your are telling it to make room for 6 images, let me explain:
1. command subplot(a,b,c) has 3 fields
2. a and b define the a rows b columns that you want the outline to size
so, because you are saying a=3 b=3, command subplot is sizing 9 spaces
3.
field c is the position of the image reading the columns left to right, sequentially.
For 3x3 c would follow this order, start reading top left corner downwards
1 4 72 5 83 6 9
your code with modified subplot indices, and this image:
format long g; format compact; captionFontSize = 14;FileName = 'dirty_water.jpg'; originalImage = imread(FileName);% Checks for grayscale images
[rows, columns, numberOfColorChannels] = size(originalImage); if numberOfColorChannels > 1 promptMessage = sprintf('Your image file has %d color channels.\nThis demo was designed for grayscale images.\nDo you want me to convert it to grayscale for you so you can continue?', numberOfColorChannels); button = questdlg(promptMessage, 'Continue', 'Convert and Continue', 'Cancel', 'Convert and Continue'); if strcmp(button, 'Cancel') fprintf(1, 'Finished running micellesDemo.m.\n'); return; endoriginalImage = rgb2gray(originalImage); endh1=figure(1);subplot(2, 2, 1); imshow(originalImage); set(gcf, 'units','normalized','outerposition',[0 0 1 1]);[pixelCount, grayLevels] = imhist(originalImage); subplot(2, 2, 2); bar(pixelCount); title('Histogram of original image', 'FontSize', captionFontSize); xlim([0 grayLevels(end)]); grid on;thresholdValue = 100; binaryImage = originalImage > thresholdValue; binaryImage = imfill(binaryImage, 'holes');% Show the threshold as a vertical red bar on the histogram. hold on;
maxYValue = ylim; line([thresholdValue, thresholdValue], maxYValue, 'Color', 'r'); annotationText = sprintf('Thresholded at %d gray levels', thresholdValue); text(double(thresholdValue + 5), double(0.5 * maxYValue(2)), annotationText, 'FontSize', 10, 'Color', [0 .5 0]); text(double(thresholdValue - 70), double(0.94 * maxYValue(2)), 'Background', 'FontSize', 10, 'Color', [0 0 .5]); text(double(thresholdValue + 50), double(0.94 * maxYValue(2)), 'Foreground', 'FontSize', 10, 'Color', [0 0 .5]);imshow(binaryImage); title('Image converted into Binary after thresholding', 'FontSize', captionFontSize);labeledImage = bwlabel(binaryImage, 8); subplot(2, 2, 3); imshow(labeledImage, []); title('Micelle groups', 'FontSize', captionFontSize); micellMeasurements = regionprops(labeledImage, originalImage, 'all'); numberOfmicell = size(micellMeasurements, 1);subplot(2, 2, 4); imshow(originalImage); title('Outlines, from bwboundaries()', 'FontSize', captionFontSize); axis image; hold on; boundaries = bwboundaries(binaryImage); numberOfBoundaries = size(boundaries, 1); for k = 1 : numberOfBoundaries thisBoundary = boundaries{k}; plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2); end; hold off;textFontSize = 14; % Used to control size of "micelle number" labels put atop the image.
labelShiftX = -7; micelleECD = zeros(1, numberOfmicell); fprintf(1,'micelle # Mean Intensity Area Perimeter Centroid Diameter\n'); for k = 1 : numberOfmicell thismicellesPixels = micellMeasurements(k).PixelIdxList; meanGL = mean(originalImage(thismicellesPixels)); meanGL2008a = micellMeasurements(k).MeanIntensity; micelleArea = micellMeasurements(k).Area; micellePerimeter = micellMeasurements(k).Perimeter; micelleCentroid = micellMeasurements(k).Centroid; micelleECD(k) = sqrt(4 * micelleArea / pi); fprintf(1,'#%2d %17.1f %11.1f %8.1f %8.1f %8.1f % 8.1f\n', k, meanGL, micelleArea, micellePerimeter, micelleCentroid, micelleECD(k)); % text(micelleCentroid(1) + labelShiftX, micelleCentroid(2), num2str(k), 'FontSize', textFontSize, 'FontWeight', 'Bold');
text(micelleCentroid(1) + labelShiftX, micelleCentroid(2), num2str(k), 'FontSize', textFontSize, 'FontWeight', 'Bold'); end
if you find my answer useful would you please mark it as Accepted Answer by clicking on the ACCEPT ANSWER button?
thanks in advance for time and attention
John BG
Best Answer