Hi. I would like to save the RGB numbers of an image (see RGB_value) inside a cell (see matrix) that has the same size as the image and in the same determined position.
imageArray = importdata("ssg.jpg"); figure() imshow(imageArray) impixelinfo row_imageArray = height(imageArray); col_imageArray = width(imageArray); matrix = {}; X = 71; Y = 35; RED = imageArray(Y,X,1); GREEN = imageArray(Y,X,2); BLUE = imageArray(Y,X,3); RGB_value = [RED, GREEN, BLUE]; matrix = [matrix,{RGB_value}];
NOTE:-
I know you said you want a cell but I think you really don't want a slow, inefficient, memory hogging cell array. I think you should use just a regular, fast and efficient double matrix. Frankly I'm not even sure why you think you want a matrix of all the pixel locations and their RGB values. Unless it's your homework which seems probable. Anyway, here is a full, extremely well commented demo to do that:
% Take an RGB Image and write all the pixel info to a csv file in the form [R, G, B, X, Y]. % It will have as many rows as pixels in the image, and have those 5 columns. % Initialization steps. clc; % Clear the command window. close all; % Close all figures (except those of imtool.) clear; % Erase all existing variables. Or clearvars if you want. workspace; % Make sure the workspace panel is showing. format long g; format compact; %---------------------------------------------------------------------------------------------------------- % Have user browse for a file, from a specified "starting folder." % For convenience in browsing, set a starting folder from which to browse. startingFolder = pwd; % or 'C:\wherever'; if ~isfolder(startingFolder) % If that folder doesn't exist, just start in the current folder. startingFolder = pwd; end % Get the name of the file that the user wants to use. defaultFileName = fullfile(startingFolder, '*.*'); [baseFileName, folder] = uigetfile(defaultFileName, 'Select an RGB image file'); if baseFileName == 0 % User clicked the Cancel button. return; end fullFileName = fullfile(folder, baseFileName)
SEE COMPLETE ANSWER CLICK THE LINK
The Herald altogether view delivering news as it happens, ensuring readers are informed in real time. Whether it's a breaking news story or an in-depth analysis, these websites give continuous content to keep their audience engaged and informed.
ReplyDelete