Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/any one help me to correct this code or help me my I have a graduation project coming soon

any one help me to correct this code or help me my I have a graduation project coming soon

PuTI / 2025-05-03
any one help me to correct this code or help me my I have a graduation project coming soon
Matlab News

clear; close all; clc;
warning(‘off’, ‘all’);

[contentFile, contentPath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة المحتوى’);
if isequal(contentFile, 0)
error(‘لم يتم اختيار صورة محتوى’);
end
contentImage = imread(fullfile(contentPath, contentFile));
[styleFile, stylePath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة النمط’);
if isequal(styleFile, 0)
error(‘لم يتم اختيار صورة نمط’);
end
styleImage = imread(fullfile(stylePath, styleFile));
contentImage = im2double(contentImage);
styleImage = im2double(styleImage);
if size(contentImage,3) == 1
contentImage = repmat(contentImage, [1 1 3]);
end
if size(styleImage,3) == 1
styleImage = repmat(styleImage, [1 1 3]);
end
styleImage = imadjust(styleImage, [0.1 0.9], []);
styleImage = imgaussfilt(styleImage, 1);
net = vgg19();
inputSize = net.Layers(1).InputSize(1:2);
% تغيير حجم الصور مع الحفاظ على التناسب
contentImage = imresize(contentImage, inputSize);
styleImage = imresize(styleImage, inputSize);
%% 4. تحديد الطبقات الصحيحة
contentLayer = ‘conv4_2’;
styleLayers = {‘conv1_1’, ‘conv2_1’, ‘conv3_1’, ‘conv4_1’, ‘conv5_1’};
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
numIterations = 500;
learningRate = 0.01;
styleWeight = 1e6;
dlContent = dlarray(contentImage, ‘SSC’);
dlTransform = dlContent;
figure;
for iter = 1:numIterations
[grad, loss] = dlfeval(@computeGradients, dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight);
dlTransform = dlTransform – learningRate * grad;

if mod(iter,50) == 0 || iter == 1
fprintf(‘التكرار %d: الخسارة الكلية=%.2f, المحتوى=%.2f, النمط=%.2fn’, …
iter, loss.total, loss.content, loss.style);

% عرض التقدم
currentImg = uint8(extractdata(dlTransform)*255);
imshow(currentImg);
title(sprintf(‘التكرار %d/%d’, iter, numIterations));
drawnow;
end
end
outputImage = uint8(extractdata(dlTransform)*255);
[~,name,ext] = fileparts(contentFile);
outputFile = fullfile(pwd, [name ‘_styled’ ext]);
imwrite(outputImage, outputFile);
fprintf(‘تم حفظ الصورة الناتجة بنجاح في: %sn’, outputFile);
function features = getStyleFeatures(styleImg, net, styleLayers)
if ~ismatrix(styleImg) && ~(ndims(styleImg)==3)
error(‘يجب أن تكون صورة النمط مصفوفة 2D أو 3D’);
end

if size(styleImg,3) ~= 3
error(‘يجب أن تحتوي صورة النمط على 3 قنوات لونية (RGB)’);
end

try
dlStyle = dlarray(styleImg, ‘SSC’);
catch
error(‘فشل تحويل صورة النمط إلى dlarray’);
end

features = struct();
for i = 1:length(styleLayers)
layer = styleLayers{i};
try
dlFeatures = activations(net, dlStyle, layer);
features.(layer) = computeGramMatrix(dlFeatures);
catch ME
error(‘فشل في استخراج خصائص الطبقة %s: %s’, layer, ME.message);
end
end
end
function gramMatrix = computeGramMatrix(features)
[H,W,C] = size(features);
reshaped = reshape(features, H*W, C);
gramMatrix = reshaped’ * reshaped / (H*W*C);
end
function [gradients, loss] = computeGradients(dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight)
contentFeatures = activations(net, dlContent, contentLayer);
transformContentFeatures = activations(net, dlTransform, contentLayer);
contentLoss = mean((transformContentFeatures – contentFeatures).^2);

styleLoss = 0;
for i = 1:length(styleLayers)
layer = styleLayers{i};
transformFeatures = activations(net, dlTransform, layer);
gramTransform = computeGramMatrix(transformFeatures);
gramStyle = styleFeatures.(layer);
styleLoss = styleLoss + mean((gramTransform – gramStyle).^2);
end
styleLoss = styleLoss / length(styleLayers);

totalLoss = contentLoss + styleWeight * styleLoss;

gradients = dlgradient(totalLoss, dlTransform);

loss.total = double(totalLoss);
loss.content = double(contentLoss);
loss.style = double(styleLoss);
end

%%%%
erorr
rror using styletransfer>getStyleFeatures (line 111)
فشل في استخراج خصائص الطبقة conv1_1: Invalid 2-D image data. Specify image data as a 3-D numeric array containing a single image, a
4-D numeric array containing multiple images, a datastore, or a table containing image file paths or images in the first column.

Error in styletransfer (line 48)
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^clear; close all; clc;
warning(‘off’, ‘all’);

[contentFile, contentPath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة المحتوى’);
if isequal(contentFile, 0)
error(‘لم يتم اختيار صورة محتوى’);
end
contentImage = imread(fullfile(contentPath, contentFile));
[styleFile, stylePath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة النمط’);
if isequal(styleFile, 0)
error(‘لم يتم اختيار صورة نمط’);
end
styleImage = imread(fullfile(stylePath, styleFile));
contentImage = im2double(contentImage);
styleImage = im2double(styleImage);
if size(contentImage,3) == 1
contentImage = repmat(contentImage, [1 1 3]);
end
if size(styleImage,3) == 1
styleImage = repmat(styleImage, [1 1 3]);
end
styleImage = imadjust(styleImage, [0.1 0.9], []);
styleImage = imgaussfilt(styleImage, 1);
net = vgg19();
inputSize = net.Layers(1).InputSize(1:2);
% تغيير حجم الصور مع الحفاظ على التناسب
contentImage = imresize(contentImage, inputSize);
styleImage = imresize(styleImage, inputSize);
%% 4. تحديد الطبقات الصحيحة
contentLayer = ‘conv4_2’;
styleLayers = {‘conv1_1’, ‘conv2_1’, ‘conv3_1’, ‘conv4_1’, ‘conv5_1’};
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
numIterations = 500;
learningRate = 0.01;
styleWeight = 1e6;
dlContent = dlarray(contentImage, ‘SSC’);
dlTransform = dlContent;
figure;
for iter = 1:numIterations
[grad, loss] = dlfeval(@computeGradients, dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight);
dlTransform = dlTransform – learningRate * grad;

if mod(iter,50) == 0 || iter == 1
fprintf(‘التكرار %d: الخسارة الكلية=%.2f, المحتوى=%.2f, النمط=%.2fn’, …
iter, loss.total, loss.content, loss.style);

% عرض التقدم
currentImg = uint8(extractdata(dlTransform)*255);
imshow(currentImg);
title(sprintf(‘التكرار %d/%d’, iter, numIterations));
drawnow;
end
end
outputImage = uint8(extractdata(dlTransform)*255);
[~,name,ext] = fileparts(contentFile);
outputFile = fullfile(pwd, [name ‘_styled’ ext]);
imwrite(outputImage, outputFile);
fprintf(‘تم حفظ الصورة الناتجة بنجاح في: %sn’, outputFile);
function features = getStyleFeatures(styleImg, net, styleLayers)
if ~ismatrix(styleImg) && ~(ndims(styleImg)==3)
error(‘يجب أن تكون صورة النمط مصفوفة 2D أو 3D’);
end

if size(styleImg,3) ~= 3
error(‘يجب أن تحتوي صورة النمط على 3 قنوات لونية (RGB)’);
end

try
dlStyle = dlarray(styleImg, ‘SSC’);
catch
error(‘فشل تحويل صورة النمط إلى dlarray’);
end

features = struct();
for i = 1:length(styleLayers)
layer = styleLayers{i};
try
dlFeatures = activations(net, dlStyle, layer);
features.(layer) = computeGramMatrix(dlFeatures);
catch ME
error(‘فشل في استخراج خصائص الطبقة %s: %s’, layer, ME.message);
end
end
end
function gramMatrix = computeGramMatrix(features)
[H,W,C] = size(features);
reshaped = reshape(features, H*W, C);
gramMatrix = reshaped’ * reshaped / (H*W*C);
end
function [gradients, loss] = computeGradients(dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight)
contentFeatures = activations(net, dlContent, contentLayer);
transformContentFeatures = activations(net, dlTransform, contentLayer);
contentLoss = mean((transformContentFeatures – contentFeatures).^2);

styleLoss = 0;
for i = 1:length(styleLayers)
layer = styleLayers{i};
transformFeatures = activations(net, dlTransform, layer);
gramTransform = computeGramMatrix(transformFeatures);
gramStyle = styleFeatures.(layer);
styleLoss = styleLoss + mean((gramTransform – gramStyle).^2);
end
styleLoss = styleLoss / length(styleLayers);

totalLoss = contentLoss + styleWeight * styleLoss;

gradients = dlgradient(totalLoss, dlTransform);

loss.total = double(totalLoss);
loss.content = double(contentLoss);
loss.style = double(styleLoss);
end

%%%%
erorr
rror using styletransfer>getStyleFeatures (line 111)
فشل في استخراج خصائص الطبقة conv1_1: Invalid 2-D image data. Specify image data as a 3-D numeric array containing a single image, a
4-D numeric array containing multiple images, a datastore, or a table containing image file paths or images in the first column.

Error in styletransfer (line 48)
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ clear; close all; clc;
warning(‘off’, ‘all’);

[contentFile, contentPath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة المحتوى’);
if isequal(contentFile, 0)
error(‘لم يتم اختيار صورة محتوى’);
end
contentImage = imread(fullfile(contentPath, contentFile));
[styleFile, stylePath] = uigetfile({‘*.bmp;*.jpg;*.png;*.tif’, ‘ملفات الصور’}, ‘اختر صورة النمط’);
if isequal(styleFile, 0)
error(‘لم يتم اختيار صورة نمط’);
end
styleImage = imread(fullfile(stylePath, styleFile));
contentImage = im2double(contentImage);
styleImage = im2double(styleImage);
if size(contentImage,3) == 1
contentImage = repmat(contentImage, [1 1 3]);
end
if size(styleImage,3) == 1
styleImage = repmat(styleImage, [1 1 3]);
end
styleImage = imadjust(styleImage, [0.1 0.9], []);
styleImage = imgaussfilt(styleImage, 1);
net = vgg19();
inputSize = net.Layers(1).InputSize(1:2);
% تغيير حجم الصور مع الحفاظ على التناسب
contentImage = imresize(contentImage, inputSize);
styleImage = imresize(styleImage, inputSize);
%% 4. تحديد الطبقات الصحيحة
contentLayer = ‘conv4_2’;
styleLayers = {‘conv1_1’, ‘conv2_1’, ‘conv3_1’, ‘conv4_1’, ‘conv5_1’};
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
numIterations = 500;
learningRate = 0.01;
styleWeight = 1e6;
dlContent = dlarray(contentImage, ‘SSC’);
dlTransform = dlContent;
figure;
for iter = 1:numIterations
[grad, loss] = dlfeval(@computeGradients, dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight);
dlTransform = dlTransform – learningRate * grad;

if mod(iter,50) == 0 || iter == 1
fprintf(‘التكرار %d: الخسارة الكلية=%.2f, المحتوى=%.2f, النمط=%.2fn’, …
iter, loss.total, loss.content, loss.style);

% عرض التقدم
currentImg = uint8(extractdata(dlTransform)*255);
imshow(currentImg);
title(sprintf(‘التكرار %d/%d’, iter, numIterations));
drawnow;
end
end
outputImage = uint8(extractdata(dlTransform)*255);
[~,name,ext] = fileparts(contentFile);
outputFile = fullfile(pwd, [name ‘_styled’ ext]);
imwrite(outputImage, outputFile);
fprintf(‘تم حفظ الصورة الناتجة بنجاح في: %sn’, outputFile);
function features = getStyleFeatures(styleImg, net, styleLayers)
if ~ismatrix(styleImg) && ~(ndims(styleImg)==3)
error(‘يجب أن تكون صورة النمط مصفوفة 2D أو 3D’);
end

if size(styleImg,3) ~= 3
error(‘يجب أن تحتوي صورة النمط على 3 قنوات لونية (RGB)’);
end

try
dlStyle = dlarray(styleImg, ‘SSC’);
catch
error(‘فشل تحويل صورة النمط إلى dlarray’);
end

features = struct();
for i = 1:length(styleLayers)
layer = styleLayers{i};
try
dlFeatures = activations(net, dlStyle, layer);
features.(layer) = computeGramMatrix(dlFeatures);
catch ME
error(‘فشل في استخراج خصائص الطبقة %s: %s’, layer, ME.message);
end
end
end
function gramMatrix = computeGramMatrix(features)
[H,W,C] = size(features);
reshaped = reshape(features, H*W, C);
gramMatrix = reshaped’ * reshaped / (H*W*C);
end
function [gradients, loss] = computeGradients(dlTransform, dlContent, net, …
contentLayer, styleLayers, styleFeatures, styleWeight)
contentFeatures = activations(net, dlContent, contentLayer);
transformContentFeatures = activations(net, dlTransform, contentLayer);
contentLoss = mean((transformContentFeatures – contentFeatures).^2);

styleLoss = 0;
for i = 1:length(styleLayers)
layer = styleLayers{i};
transformFeatures = activations(net, dlTransform, layer);
gramTransform = computeGramMatrix(transformFeatures);
gramStyle = styleFeatures.(layer);
styleLoss = styleLoss + mean((gramTransform – gramStyle).^2);
end
styleLoss = styleLoss / length(styleLayers);

totalLoss = contentLoss + styleWeight * styleLoss;

gradients = dlgradient(totalLoss, dlTransform);

loss.total = double(totalLoss);
loss.content = double(contentLoss);
loss.style = double(styleLoss);
end

%%%%
erorr
rror using styletransfer>getStyleFeatures (line 111)
فشل في استخراج خصائص الطبقة conv1_1: Invalid 2-D image data. Specify image data as a 3-D numeric array containing a single image, a
4-D numeric array containing multiple images, a datastore, or a table containing image file paths or images in the first column.

Error in styletransfer (line 48)
styleFeatures = getStyleFeatures(styleImage, net, styleLayers);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ai, fast style transfer, deep learning, transfer learning MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Solid creation Simulink, simscape multibody: stuck in loading
2025-05-12

Solid creation Simulink, simscape multibody: stuck in loading

Warning: Error updating FunctionLine in using fplot
2025-05-12

Warning: Error updating FunctionLine in using fplot

Issues with EMG Signal Acquisition via Simulink Desktop Real-Time (SDRT) and DAQ Board Usage
2025-05-12

Issues with EMG Signal Acquisition via Simulink Desktop Real-Time (SDRT) and DAQ Board Usage

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss