TUT7
TUT7
%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
for i = 1:length(imageFiles)
img = imread(imageFiles{i});
if size(img, 3) == 3
img = rgb2gray(img);
end
X = X(:);
Y = Y(:);
pixelValues = double(img(:));
figure;
colorbar;
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
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(:)));
figure;
subplot(1, 2, 1);
imshow(img);
subplot(1, 2, 2);
imshow(stretchedImg);
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
>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59
>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59
>> untitled6
Image 1 at row=15, column=45:
NIR (Red channel): 103
Red (Green channel): 135
Green (Blue channel): 59
>>
%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