first example i got a good image. and NG image. Can the NG image be divided into sectors and do image processing? and thereafter prompt out which sector has missing component or misalign? please help. thank you.
MATLAB: Example i have a image of 768×1024. how to sector a image so that i can do individual processing ? etc. image subtraction.
image processingImage Processing Toolboximage subtractionMATLAB and Simulink Student Suite
Related Solutions
Lots of things could be called that - there are maybe a dozen, or more, variants. Here's an example of how I use an adaptive median filter to remove salt and pepper noise. Feel free to adapt it to your particular algorithm.
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');baseFileName = 'peppers.png';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);% Display the original color image.
subplot(3, 4, 1);imshow(rgbImage);title('Original color Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize')); % Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);greenChannel = rgbImage(:, :, 2);blueChannel = rgbImage(:, :, 3);% Display the individual red, green, and blue color channels.
subplot(3, 4, 2);imshow(redChannel);title('Red Channel', 'FontSize', fontSize);subplot(3, 4, 3);imshow(greenChannel);title('Green Channel', 'FontSize', fontSize);subplot(3, 4, 4);imshow(blueChannel);title('Blue Channel', 'FontSize', fontSize);% Generate a noisy image. This has salt and pepper noise independently on
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'salt & pepper', 0.05);subplot(3, 4, 5);imshow(noisyRGB);title('Image with Salt and Pepper Noise', 'FontSize', fontSize);% Extract the individual red, green, and blue color channels.redChannel = noisyRGB(:, :, 1);greenChannel = noisyRGB(:, :, 2);blueChannel = noisyRGB(:, :, 3);% Display the noisy channel images.
subplot(3, 4, 6);imshow(redChannel);title('Noisy Red Channel', 'FontSize', fontSize);subplot(3, 4, 7);imshow(greenChannel);title('Noisy Green Channel', 'FontSize', fontSize);subplot(3, 4, 8);imshow(blueChannel);title('Noisy Blue Channel', 'FontSize', fontSize);% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);greenMF = medfilt2(greenChannel, [3 3]);blueMF = medfilt2(blueChannel, [3 3]);% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;noiseFreeRed(noiseImage) = redMF(noiseImage);% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;noiseFreeGreen(noiseImage) = greenMF(noiseImage);% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;noiseFreeBlue(noiseImage) = blueMF(noiseImage);% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);subplot(3, 4, 9);imshow(rgbFixed);title('Restored Image', 'FontSize', fontSize);
Sucharita: Here, I've done 95% of it for you. If I do much more, then you'd just be turning in my answer as your own and I don't think your course rules allow that. You just need to replace the line that says "% code" with your own code and then display the output image after the loop is done.
% Demo to find color distances in RGB color space. By Image Analyst, May 26, 2020.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 16;fprintf('Beginning to run %s.m ...\n', mfilename);a1 = [134, 51, 143]a2 = [131, 132, 4]R0 = 30%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = pwd;baseFileName = 'image.jpeg';fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);[rows, columns, numberOfColorChannels] = size(rgbImage);% Display the test image full size.
subplot(2, 2, 1);imshow(rgbImage, []);axis('on', 'image');caption = sprintf('Reference Image : "%s"', baseFileName);title(caption, 'FontSize', fontSize, 'Interpreter', 'None');drawnow;hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;hFig1.Units = 'Normalized';hFig1.WindowState = 'maximized';% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';[rows, columns, numberOfColorChannels] = size(rgbImage);outputImage = zeros(rows, columns, numberOfColorChannels, class(rgbImage));distanceImage = zeros(rows, columns);for col = 1 : columns for row = 1 : rows thisR = double(rgbImage(row, col, 1)); thisG = double(rgbImage(row, col, 2)); thisB = double(rgbImage(row, col, 3)); distanceImage(row, col) = sqrt((thisR - a1(1))^2 + (thisG - a1(2))^2 + (thisB - a1(3))^2); % or a2 for case ii
if distanceImage(row, col) < R0 % code...
end endendmaxDistance = max(distanceImage(:))% Display the distance image.
subplot(2, 2, 2);imshow(distanceImage, []);axis('on', 'image');caption = sprintf('Distance Image : "%s"', baseFileName);title(caption, 'FontSize', fontSize, 'Interpreter', 'None');colorbar;drawnow;hp = impixelinfo(); % Set up status line to see values when you mouse over the image.% Display the histogram of the distance image.
subplot(2, 2, 3);histogram(distanceImage, 256);grid on;title('Histogram of Color Distances', 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Gray Level', 'FontSize', fontSize, 'Interpreter', 'None');ylabel('Count', 'FontSize', fontSize, 'Interpreter', 'None');fprintf('Done running %s.m ...\n', mfilename);
Best Answer