Read .png image and perform commands (example given)

3 visualizaciones (últimos 30 días)
Ilyass Boukhari
Ilyass Boukhari el 17 de Dic. de 2020
Comentada: Image Analyst el 17 de Dic. de 2020
Hello,
I have been given a list of commands from my teacher for a matlab .png image, and I am trying to replicate the same with an image of my choice (same .png).
With the image of my choice Matlab won't read it as comes up with some errors.
Below the working command+image I have been given. File name: ReadTiffImageDataExample_01.png
%%
% Example 2:
% Read in a .png image into MATLAB, and display it:
t = Tiff('peppers_RGB_tiled.tif','r');
imageData = read(t);
% Display the image.
figure(2)
imshow(imageData);
title('Peppers Image (RGB)')
%% % Example 3:
% Display Just Y component of an image that has been read into MATLAB:
t = Tiff('peppers_YCbCr_tiled.tif','r');
[Y,Cb,Cr] = read(t);
%Display the Y component of the image:
figure(3)
imshow(Y);
title('Peppers Image (Y Component)');
%%
% Example 4:
% In a 2D image, find the locations of all pixels whose value is above a
% chosen threshold:
% Fist, set all pixels of Y-component of image that are below a certain Threshold to
% zero:
% First choose threshold (example 200; could relate to a threshold
% temperature if this were a temperature-scaled image from a thermal camera, for exmaple)
Threshold = 150;
% Load Y-component of image data into a matrix, ready to be threshold checked:
Thresholded_Matrix = Y;
% Set all pixel values less than Threshold to zero:
Thresholded_Matrix(Thresholded_Matrix<Threshold)=0;
% Display Thresholded_Matrix:
figure(4)
imshow(Thresholded_Matrix);
% Find the indices (matrix row and column numbers) of locations where the
% pixel value of the Y-component image data is greater than Threshold;
%(these would correspond to x,y coordinates of places on the image where
% pixel value is above the threshold, and hence, if this where a temperature-scaled thermal
% camera image, for example, would be the 2D spatial coordinates
% (assuming 2D plan-view image capture from above)of places
% in the image that are above the temperature threshold):
% Display as row and column coordinates in the command window:
linearIndexes = find(Y>Threshold);
[rows, columns] = ind2sub(size(Y), linearIndexes)
% Also plot the Thresholded Matrix as a sruface:
figure(5)
surf(Thresholded_Matrix);
Below the result of what I really need, part of "Example 4" (but I believe that pieces of code in the previous examples might be needed for this)
Now, this is my image which matlab doesn't read, therefore cannot perform the commands above. File name: flir.png
load('flir.png');
a = Tiff('flir_YCbCr_tiled.tif','r');
[Y,Cb,Cr] = read(a);
>> fire1
Error using Tiff (line 651)
Could not open file 'flir_YCbCr_tiled.tif'.
Error in fire1 (line 3)
a = Tiff('flir_YCbCr_tiled.tif','r');
How can I perform the same commands with my image? Am I starting with the right commands?

Respuesta aceptada

Image Analyst
Image Analyst el 17 de Dic. de 2020
You don't have a file called 'flir_YCbCr_tiled.tif' on your search path. So just replace load(), a=, and this:
t = Tiff('peppers_RGB_tiled.tif','r');
imageData = read(t);
with this
fileName = 'flir.png';
imageData = imread(fileName);
  4 comentarios
Ilyass Boukhari
Ilyass Boukhari el 17 de Dic. de 2020
I'd be pleased to accept your answer, however there is something wrong, as this is the result
It appears with the pepper image example, where I'm looking to make it work for my image.
is the problem with this code?
rgbImage = imread('peppers_YCbCr_tiled.tif');
Image Analyst
Image Analyst el 17 de Dic. de 2020
Read in whatever image you want/need to read in. If you want the flir image, read that in instead of the peppers image:
rgbImage = imread('flir.png');
ycbcrImage = rgb2ycbcr(rgbImage);
[Y,Cb,Cr] = imsplit(ycbcrImage);
imshow(Y, []);

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by