how to solve image process error using MATLAB

18 views (last 30 days)
Loading Images, converting color image to grayscale, writing the image into a file
A='D:\.. ..\img1.bmp';
B=imread(A,'bmp');
figure(1),imshow(B);
C=rgb2gray(B);
figure(2),imshow(C);
imwrite(C,'C:\Users\pc\Desktop\.. ..\imgwrite1.jpg','jpg');
A = im2double(B)
%{
I2 = im2double(I) converts the intensity image I to double precision,
rescaling the data if necessary.
I can be a grayscale intensity image, a truecolor image, or a binary image.
If the input image is of class double,
then the output image is identical.
%}
H=im2double(imread(A,'bmp'));
%{
Adjust image intensity values or colormap
= imadjust(I,[low_in; high_in],[low_out; high_out]) maps the values in I to new values in J
such that values between low_in and high_in map to values between low_out and high_out.
Note If high_out is less than low_out,
imadjust reverses the output image, as in a photographic negative.
%}
C=imadjust(B,[0 1],[1 0]);
%Enhance contrast using histogram equalization
E=histeq(B);
%{
level = graythresh(I) computes a global threshold (level) that can be used to convert an intensity image to a binary image
with im2bw.
level is a normalized intensity value that lies in the range [0, 1].
%}
F = graythresh(B);
%{
BW = im2bw(I, level)
converts the grayscale image I to a binary image.
The output image BW replaces all pixels in
the input image with luminance greater than level with the value 1 (white)
and replaces all other pixels with the value 0 (black)
%}
G= im2bw(B,F);
A='D:\.. .. \img1.bmp';
H=im2double(imread(A,'bmp'));
figure(1), imshow(H);
B= rgb2gray(H);
figure(2), imshow(B);
C=imadjust(B,[0 1],[1 0]);
figure(3),imshow(C);
E=histeq(B);
figure(4), imshow(E);
F = graythresh(B);
G= im2bw(B,F);
figure(5), imshow(G);
Adding salt and pepper noise to an image
II = imread('eight.tif'); I=rgb2gray(II);
J = imnoise(I,'salt & pepper');
figure, imshow(I)
figure, imshow(J)
Filtering noise using median filter
II = imread('eight.tif');I=rgb2gray(II);
J = imnoise(I,'salt & pepper');
figure, imshow(I)
figure, imshow(J)
k=medfilt2(J);figure, imshow(k);
I=imread('rice.tif'); % load MATLAB image
subplot(2,2,1);
imshow(I); title('original image');
h=fspecial('sobel');
A=imfilter(I,h);
subplot(2,2,2);
imshow(A);title('horizontal sobel');
B=edge(I,'sobel',[],'both');
subplot(2,2,3);imshow(B);title('sobel');
C=edge(I,'canny',[],1);
subplot(2,2,4);imshow(C);title('canny');
}ii=imread('eight.tif');
i=rgb2gray(ii);
h=fspecial('sobel'); % creat sobel hz edge detection
a=imfilter(i,h);% to get vertival direction use h’
b=edge(i,'sobel',[],'both');% filter sobel in both directions
c=edge(i,'canny',[],1);% canny edge detection and 1 is the standard deviation of gaussian filter
subplot(2,2,1),imshow(i);% original image
subplot(2,2,2),imshow(a);% hz sobel
subplot(2,2,3), imshow(b);% sobel both directions
subplot(2,2,4), imshow(c);% canny edge detection

Answers (1)

DGM
DGM on 11 Dec 2022
There are many errors. I'm just going to add comments. This needs a lot of cleanup.
A='peppers.png'; % <-- i'm using this instead
B=imread(A);
figure(1),imshow(B);
C=rgb2gray(B);
figure(2),imshow(C);
imwrite(C,'c.jpg'); % <-- i'm using this instead
A = im2double(B);
%{
I2 = im2double(I) converts the intensity image I to double precision,
rescaling the data if necessary.
I can be a grayscale intensity image, a truecolor image, or a binary image.
If the input image is of class double,
then the output image is identical.
%}
%H=im2double(imread(A)); % <-- A is a numeric array, not a filename
H=im2double(A);
%{
Adjust image intensity values or colormap
= imadjust(I,[low_in; high_in],[low_out; high_out]) maps the values in I to new values in J
such that values between low_in and high_in map to values between low_out and high_out.
Note If high_out is less than low_out,
imadjust reverses the output image, as in a photographic negative.
%}
C=imadjust(B,[0 1],[1 0]);
%Enhance contrast using histogram equalization
E=histeq(B);
%{
level = graythresh(I) computes a global threshold (level) that can be used to convert an intensity image to a binary image
with im2bw.
level is a normalized intensity value that lies in the range [0, 1].
%}
F = graythresh(B);
%{
BW = im2bw(I, level)
converts the grayscale image I to a binary image.
The output image BW replaces all pixels in
the input image with luminance greater than level with the value 1 (white)
and replaces all other pixels with the value 0 (black)
%}
G= im2bw(B,F);
%%
A='peppers.png';
H=im2double(imread(A));
figure(1), imshow(H);
B= rgb2gray(H);
figure(2), imshow(B);
C=imadjust(B,[0 1],[1 0]);
figure(3),imshow(C);
E=histeq(B);
figure(4), imshow(E);
F = graythresh(B);
G= im2bw(B,F);
figure(5), imshow(G);
%% these entire blocks are redundant; delete one
%Adding salt and pepper noise to an image
II = imread('eight.tif');
%I=rgb2gray(II); % <-- II is not an RGB image
I = II; % <-- i'm using this instead
J = imnoise(I,'salt & pepper');
figure, imshow(I)
figure, imshow(J)
%Filtering noise using median filter
II = imread('eight.tif');
%I=rgb2gray(II); % <-- II is not an RGB image
I = II; % <-- i'm using this instead
J = imnoise(I,'salt & pepper');
figure, imshow(I)
figure, imshow(J)
%%
k=medfilt2(J);figure, imshow(k);
%I=imread('rice.tif'); % <-- file does not exist
I=imread('rice.png'); % <-- i'm using this instead
subplot(2,2,1);
imshow(I); title('original image');
h=fspecial('sobel');
A=imfilter(I,h);
subplot(2,2,2);
imshow(A);title('horizontal sobel');
B=edge(I,'sobel',[],'both');
subplot(2,2,3);imshow(B);title('sobel');
C=edge(I,'canny',[],1);
subplot(2,2,4);imshow(C);title('canny');
%}ii=imread('eight.tif'); % <-- dangling }
ii=imread('eight.tif'); % removed
%i=rgb2gray(ii); % <-- again, ii is not an RGB image
i = ii; % <-- i'm using this instead
h=fspecial('sobel'); % creat sobel hz edge detection
a=imfilter(i,h);% to get vertival direction use h’
b=edge(i,'sobel',[],'both');% filter sobel in both directions
c=edge(i,'canny',[],1);% canny edge detection and 1 is the standard deviation of gaussian filter
subplot(2,2,1),imshow(i);% original image
subplot(2,2,2),imshow(a);% hz sobel
subplot(2,2,3), imshow(b);% sobel both directions
subplot(2,2,4), imshow(c);% canny edge detection

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!