0% found this document useful (0 votes)
3 views11 pages

TUT7

The document contains a series of MATLAB scripts for processing a set of images, including converting to grayscale, generating histograms, creating scatter plots, applying contrast stretching, and calculating NDVI. Each section demonstrates different image analysis techniques, such as enhancing visibility of details and visualizing pixel intensity distributions. The outputs include visualizations and printed pixel values for specific image channels, aiding in image processing tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

TUT7

The document contains a series of MATLAB scripts for processing a set of images, including converting to grayscale, generating histograms, creating scatter plots, applying contrast stretching, and calculating NDVI. Each section demonstrates different image analysis techniques, such as enhancing visibility of details and visualizing pixel intensity distributions. The outputs include visualizations and printed pixel values for specific image channels, aiding in image processing tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

%sai rojitha-ch23b095

%question 1
imageFiles = {'Image_1_T7.jpg', 'Image_2_T7.jpg', 'Image_3_T7.jpg'};
for i = 1:3
image = imread(imageFiles{i});
if size(image, 3) == 3
grayImage = rgb2gray(image);
else
grayImage = image;
end
figure;
subplot(1, 2, 1);
imshow(image);
title(['Original Image ', num2str(i)]);
subplot(1, 2, 2);
imhist(grayImage);
title(['Histogram of Image ', num2str(i)]);
xlabel('Pixel Intensity');
ylabel('Frequency');
end
Output
Fig 1
Fig 2
Fig 3
%question2

imageFiles = {'Image_1_T7.jpg', 'Image_2_T7.jpg', 'Image_3_T7.jpg'};

for i = 1:length(imageFiles)

img = imread(imageFiles{i});

if size(img, 3) == 3

img = rgb2gray(img);

end

[rows, cols] = size(img);

[X, Y] = meshgrid(1:cols, 1:rows);

X = X(:);

Y = Y(:);

pixelValues = double(img(:));

figure;

scatter3(X, Y, pixelValues, 5, pixelValues, 'filled');

colorbar;

xlabel('X'); ylabel('Y'); zlabel('Pixel Intensity');

title(['Scatter Plot of Image ', num2str(i)]);

end

Output
Scatter plots for images typically reveal patterns in intensity values across spatial positions:
Clusters indicate regions with similar intensities, often representing objects or textures.
Flat regions in intensity may represent background areas with minimal detail.
Gradients show gradual changes in intensity, which could imply lighting variations or shading
effects.
This visualization can help in analyzing texture, lighting consistency, and identifying regions of
interest in image processing tasks.
%question 3

imageFiles = {'Image_1_T7.jpg', 'Image_2_T7.jpg', 'Image_3_T7.jpg'};

for i = 1:length(imageFiles)

img = imread(imageFiles{i});

if size(img, 3) == 3

img1 = rgb2gray(img);

end

minPixel = double(min(img1(:)));

maxPixel = double(max(img1(:)));

stretchedImg = uint8(255 * (double(img1) - minPixel) / (maxPixel -


minPixel));

figure;

subplot(1, 2, 1);

imshow(img);

title(['Original Image ', num2str(i)]);

subplot(1, 2, 2);

imshow(stretchedImg);

title(['Contrast-Stretched Image ', num2str(i)]);

end

Output
Contrast stretching enhances the visibility of details, particularly in images with low contrast:
Improved Detail Visibility: Dark or bright regions in the original images become more
distinguishable, revealing finer details.
Enhanced Edges and Features: Sharpens edges and enhances textures, making objects within
the image more identifiable.
Brightness and Clarity: Overall brightness improves, and the image appears clearer with a more
balanced intensity range.
This technique is beneficial when analyzing images with poor contrast, such as underexposed
or overexposed photos, as it makes subtle features more perceptible.
%question 4
imageFiles = {'Image_1_T7.jpg', 'Image_2_T7.jpg', 'Image_3_T7.jpg'};
row = 15;
col = 45;
for i = 1:length(imageFiles)
img = imread(imageFiles{i});
if size(img, 3) == 3
redChannel = img(row, col, 1);
greenChannel = img(row, col, 2);
blueChannel = img(row, col, 3);
fprintf('Image %d at row=%d, column=%d:\n', i, row, col);
fprintf(' NIR (Red channel): %d\n', redChannel);
fprintf(' Red (Green channel): %d\n', greenChannel);
fprintf(' Green (Blue channel): %d\n\n', blueChannel);
else
fprintf('Image %d is not in RGB format.\n',i);
end
end
Output
>> untitled
>> untitled
>> untitled
>> untitled
>> untitled
>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59

Image 2 at row=15, column=45:


NIR (Red channel): 0
Red (Green channel): 0
Green (Blue channel): 0

Image 3 at row=15, column=45:


NIR (Red channel): 255
Red (Green channel): 255
Green (Blue channel): 253

>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59

Image 2 at row=15, column=45:


NIR (Red channel): 0
Red (Green channel): 0
Green (Blue channel): 0

Image 3 at row=15, column=45:


NIR (Red channel): 255
Red (Green channel): 255
Green (Blue channel): 253

>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59

Image 2 at row=15, column=45:


NIR (Red channel): 0
Red (Green channel): 0
Green (Blue channel): 0

Image 3 at row=15, column=45:


NIR (Red channel): 255
Red (Green channel): 255
Green (Blue channel): 253

>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59

Image 2 at row=15, column=45:


NIR (Red channel): 0
Red (Green channel): 0
Green (Blue channel): 0
Image 3 at row=15, column=45:
NIR (Red channel): 255
Red (Green channel): 255
Green (Blue channel): 253

>>
%question 5
imageFiles = {'Image_1_T7.jpg', 'Image_2_T7.jpg', 'Image_3_T7.jpg'};
for i = 1:length(imageFiles)
img = imread(imageFiles{i});
NIR = double(img(:,:,1));
Red = double(img(:,:,2));
NDVI = (NIR - Red) ./ (NIR + Red);
figure;
imagesc(NDVI);
colormap('jet');
colorbar;
clim([-1 1]);
axis image;
title(['NDVI Image for Image ', num2str(i)]);
xlabel('X');
ylabel('Y');
end
Output

You might also like